Java Code Examples for java.util.Calendar.getInstance()

The following are Jave code examples for showing how to use getInstance() of the java.util.Calendar class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: airgram   File: LocaleController.java   View Source Code Vote up 6 votes
public static String formatDateChat(long date) {
    try {
        Calendar rightNow = Calendar.getInstance();
        int year = rightNow.get(Calendar.YEAR);

        rightNow.setTimeInMillis(date * 1000);
        int dateYear = rightNow.get(Calendar.YEAR);

        if (year == dateYear) {
            return getInstance().chatDate.format(date * 1000);
        }
        return getInstance().chatFullDate.format(date * 1000);
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }
    return "LOC_ERR: formatDateChat";
}
 
Example 2
Project: FakeWeather   File: TimeUtils.java   View Source Code Vote up 6 votes
/**
 * 判断当前时间是否在两个时间段之内
 *
 * @param beginTime 开始时间
 * @param endTime   结束时间
 * @return
 */
public static boolean isNowBetween(String beginTime, String endTime) {
    SimpleDateFormat df = new SimpleDateFormat("HH:mm");
    Date now = null;
    Date begin = null;
    Date end = null;
    try {
        now = df.parse(df.format(new Date()));
        begin = df.parse(beginTime);
        end = df.parse(endTime);
    } catch (Exception e) {
        e.printStackTrace();
    }
    Calendar nowCal = Calendar.getInstance();
    nowCal.setTime(now);

    Calendar beginCal = Calendar.getInstance();
    beginCal.setTime(begin);

    Calendar endCal = Calendar.getInstance();
    endCal.setTime(end);

    if (nowCal.after(beginCal) && nowCal.before(endCal)) {
        return true;
    } else {
        return false;
    }
}
 
Example 3
Project: phonk   File: SchedulerManager.java   View Source Code Vote up 6 votes
public void addAlarm(Date date, int id, String data, int interval, boolean repeating, boolean wakeUpScreen) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);

    SimpleDateFormat format = new SimpleDateFormat("EEEE, MMMM d, yyyy 'at' h:mm a");

    // intent
    Intent intent = new Intent(c, AlarmReceiver.class);
    intent.putExtra(ALARM_INTENT, data);
    intent.putExtra(Project.SETTINGS_SCREEN_WAKEUP, wakeUpScreen);
    intent.putExtra(Project.NAME, mProject.getName());
    intent.putExtra(Project.FOLDER, mProject.getFolder());
    PendingIntent sender = PendingIntent.getBroadcast(c, id, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    // Set Alarm
    if (repeating) mAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), interval, sender);
    else mAlarmManager.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), sender);

    // add to a global alarm thingie
    addTask(new Task(id, mProject, Task.TYPE_ALARM ,cal, interval, repeating, wakeUpScreen));
}
 
Example 4
Project: alfresco-remote-api   File: BlogPostsPerMonthGet.java   View Source Code Vote up 5 votes
/**
 * Ported from blog-posts-per-month.get.js
 */
@SuppressWarnings("deprecation")
private Date getBeginOfMonthDate(Date date)
{
    //TODO These date processing methods are copied almost verbatim from JavaScript to preserve behaviour.
    // However they should be updated to use java.util.Calendar as the current implementation assumes a Gregorian calendar.
    Calendar calendar = Calendar.getInstance();
    calendar.set(date.getYear(), date.getMonth(), 1);
    return calendar.getTime();
}
 
Example 5
Project: opencps-v2   File: DateTimeUtils.java   View Source Code Vote up 5 votes
public static int getMonthFromDate(Date date) {
	int month = 1;

	if (date != null) {
		Calendar calendar = Calendar.getInstance();

		calendar.setTime(date);
		month = calendar.get(Calendar.MONTH);

		calendar.setTime(date);
		month = calendar.get(Calendar.MONTH);
	}

	return month;
}
 
Example 6
Project: thingweb-directory   File: ThingDescription.java   View Source Code Vote up 5 votes
public ThingDescription(String id, String time) {
	
	DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
	this.id = id;
	this.lifetime = Calendar.getInstance();
	try {
		this.lifetime.setTime(dateFormat.parse(time));
	} catch (ParseException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
Example 7
Project: openjdk-jdk10   File: JapaneseDate.java   View Source Code Vote up 5 votes
@Override
public int lengthOfYear() {
    Calendar jcal = Calendar.getInstance(JapaneseChronology.LOCALE);
    jcal.set(Calendar.ERA, era.getValue() + JapaneseEra.ERA_OFFSET);
    jcal.set(yearOfEra, isoDate.getMonthValue() - 1, isoDate.getDayOfMonth());
    return  jcal.getActualMaximum(Calendar.DAY_OF_YEAR);
}
 
Example 8
Project: DateRangePicker   File: CalendarPickerView.java   View Source Code Vote up 5 votes
@Override public void handleClick(MonthCellDescriptor cell) {
  Date clickedDate = cell.getDate();

  if(highlightedCells.contains(cell)){
    return;
  }

  Calendar calendar = Calendar.getInstance();
  calendar.setTime(clickedDate);

  int day = calendar.get(DAY_OF_WEEK);
  if(deactivatedDates.contains(day)){
    return;
  }

  if (cellClickInterceptor != null && cellClickInterceptor.onCellClicked(clickedDate)) {
    return;
  }
  if (!betweenDates(clickedDate, minCal, maxCal) || !isDateSelectable(clickedDate)) {
    if (invalidDateListener != null) {
      invalidDateListener.onInvalidDateSelected(clickedDate);
    }
  } else {
    boolean wasSelected = doSelectDate(clickedDate, cell);

    if (dateListener != null) {
      if (wasSelected) {
        dateListener.onDateSelected(clickedDate);
      } else {
        dateListener.onDateUnselected(clickedDate);
      }
    }
  }
}
 
Example 9
Project: belling-spring-rabbitmq   File: TimeUtils.java   View Source Code Vote up 5 votes
public static String getLastmondayInt() {

		Calendar cal = Calendar.getInstance();
		cal.setTime(new Date());
		cal.add(Calendar.DAY_OF_MONTH, getMondayPlus() - 7);

		return format(cal.getTime(), "yyyyMMdd");
	}
 
Example 10
Project: reading-and-annotate-rocketmq-3.4.6   File: UtilAll.java   View Source Code Vote up 5 votes
public static long computNextHourTimeMillis() {
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(System.currentTimeMillis());
    cal.add(Calendar.DAY_OF_MONTH, 0);
    cal.add(Calendar.HOUR_OF_DAY, 1);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);

    return cal.getTimeInMillis();
}
 
Example 11
Project: OpenVertretung   File: ResultSetImpl.java   View Source Code Vote up 5 votes
protected Calendar getGmtCalendar() {
    // Worst case we allocate this twice and the other gets GC'd,
    // however prevents deadlock
    if (this.gmtCalendar == null) {
        this.gmtCalendar = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    }

    return this.gmtCalendar;
}
 
Example 12
Project: financisto1-holo   File: TransactionsListAdapter.java   View Source Code Vote up 4 votes
@Override
protected void bindView(BlotterViewHolder v, Context context, Cursor cursor) {
    long toAccountId = cursor.getLong(BlotterColumns.to_account_id.ordinal());
    String payee = cursor.getString(BlotterColumns.payee.ordinal());
    String note = cursor.getString(BlotterColumns.note.ordinal());
    long locationId = cursor.getLong(BlotterColumns.location_id.ordinal());
    String location = "";
    if (locationId > 0) {
        location = cursor.getString(BlotterColumns.location.ordinal());
    }
    String toAccount = cursor.getString(BlotterColumns.to_account_title.ordinal());
    long fromAmount = cursor.getLong(BlotterColumns.from_amount.ordinal());
    if (toAccountId > 0) {
        v.topView.setText(R.string.transfer);
        if (fromAmount > 0) {
            note = toAccount+" \u00BB";
        } else {
            note = "\u00AB "+toAccount;
        }
        u.setTransferTextColor(v.centerView);
    } else {
        String title = cursor.getString(BlotterColumns.from_account_title.ordinal());
        v.topView.setText(title);
        v.centerView.setTextColor(Color.WHITE);
    }

    long categoryId = cursor.getLong(BlotterColumns.category_id.ordinal());
    String category = "";
    if (categoryId != 0) {
        category = cursor.getString(BlotterColumns.category_title.ordinal());
    }
    String text = generateTransactionTitle(sb, payee, note, location, categoryId, category);
    v.centerView.setText(text);
    sb.setLength(0);

    long currencyId = cursor.getLong(BlotterColumns.from_account_currency_id.ordinal());
    Currency c = CurrencyCache.getCurrency(em, currencyId);
    long originalCurrencyId = cursor.getLong(BlotterColumns.original_currency_id.ordinal());
    if (originalCurrencyId > 0) {
        Currency originalCurrency = CurrencyCache.getCurrency(em, originalCurrencyId);
        long originalAmount = cursor.getLong(BlotterColumns.original_from_amount.ordinal());
        u.setAmountText(sb, v.rightCenterView, originalCurrency, originalAmount, c, fromAmount, true);
    } else {
        u.setAmountText(v.rightCenterView, c, fromAmount, true);
    }
    if (fromAmount > 0) {
        v.iconView.setImageDrawable(icBlotterIncome);
    } else if (fromAmount < 0) {
        v.iconView.setImageDrawable(icBlotterExpense);
    }

    long date = cursor.getLong(BlotterColumns.datetime.ordinal());
    v.bottomView.setText(DateUtils.formatDateTime(context, date,
            DateUtils.FORMAT_SHOW_DATE|DateUtils.FORMAT_SHOW_WEEKDAY|DateUtils.FORMAT_ABBREV_WEEKDAY|DateUtils.FORMAT_SHOW_TIME|DateUtils.FORMAT_ABBREV_MONTH));
    if (date > System.currentTimeMillis()) {
        u.setFutureTextColor(v.bottomView);
    } else {
        Calendar cal = Calendar.getInstance();
        cal.setTimeInMillis(date);
        int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
        if (dayOfWeek == Calendar.SUNDAY || dayOfWeek == Calendar.SATURDAY) {
            v.bottomView.setTextColor(Color.rgb(224, 112, 112));
        } else {
            v.bottomView.setTextColor(v.topView.getTextColors().getDefaultColor());
        }
    }

    long balance = cursor.getLong(BlotterColumns.from_account_balance.ordinal());
    v.rightView.setText(Utils.amountToString(c, balance, false));
    removeRightViewIfNeeded(v);
    setIndicatorColor(v, cursor);
}
 
Example 13
Project: boohee_v5.6   File: DateUtils.java   View Source Code Vote up 4 votes
public static Date getDay(String dateString, int dayNum) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(string2date(dateString, "yyyy-MM-dd"));
    cal.add(5, dayNum);
    return cal.getTime();
}
 
Example 14
Project: apache-tomcat-7.0.73-with-comment   File: JspCalendar.java   View Source Code Vote up 4 votes
public JspCalendar() {
    calendar = Calendar.getInstance();
    Date trialTime = new Date();
    calendar.setTime(trialTime);
}
 
Example 15
Project: chromium-for-android-56-debug-video   File: CardUnmaskPrompt.java   View Source Code Vote up 4 votes
@Override
protected Calendar doInBackground(Void... unused) {
    return Calendar.getInstance();
}
 
Example 16
Project: L2J-Global   File: GraciaSeedsManager.java   View Source Code Vote up 4 votes
protected GraciaSeedsManager()
{
	_SoDLastStateChangeDate = Calendar.getInstance();
	loadData();
	handleSodStages();
}
 
Example 17
Project: mvvm-template   File: DatesUtils.java   View Source Code Vote up 3 votes
/**
 * Get the day of week from a date.
 * 0 for SUN.
 * 1 for MON.
 * .
 * .
 * .
 * 6 for SAT.
 *
 * @param year
 *         The year of the date.
 * @param month
 *         The month of the date.
 * @param day
 *         The day of month of the date.
 * @return Integer to determine the day of week.
 */
@SuppressLint("WrongConstant") public static int getWeekDayFromDate(int year, int month, int day) {
    Calendar calendar = Calendar.getInstance();
    calendar.set(year, month - 1, day);
    calendar.add(Calendar.SECOND, 0);
    calendar.setFirstDayOfWeek(Calendar.SUNDAY);
    return calendar.get(Calendar.DAY_OF_WEEK) - 1;
}
 
Example 18
Project: meuboleto   File: ExampleUnitTest.java   View Source Code Vote up 3 votes
@Test
public void date_isCorrect() throws Exception {
    Date now = new Date();

    Calendar c = Calendar.getInstance();
    c.add(Calendar.DATE, 1);  // number of days to add

    //assertEquals(true,  now.before(c.getTime()));
    assertEquals(true,  c.getTime().after(now));


}
 
Example 19
Project: uavstack   File: DateTimeHelper.java   View Source Code Vote up 3 votes
public static Date getYearAgo(Date date) {

        Calendar now = Calendar.getInstance();
        now.setTime(date);

        now.add(Calendar.YEAR, -1);

        return now.getTime();
    }
 
Example 20
Project: 19porn   File: Kits.java   View Source Code Vote up 2 votes
/**
 * 获取月份
 *
 * @param mills
 * @return
 */
public static int getMonth(long mills) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(mills);
    return calendar.get(Calendar.MONTH) + 1;
}