Java Utililty Methods Calendar Time

List of utility methods to do Calendar Time

Description

The list of methods to do Calendar Time are organized into topic(s).

Method

DategetClientCurrentDate(final Calendar calendar, final TimeZone timeZone)
Get current date according to client's time zone.
Calendar result = new GregorianCalendar(timeZone);
result.setTimeInMillis(calendar.getTimeInMillis() + timeZone.getOffset(calendar.getTimeInMillis())
        - TimeZone.getDefault().getOffset(calendar.getTimeInMillis()));
result.getTime();
return result.getTime();
StringgetCurrentTimeDecimal(Calendar cal)
get Current Time Decimal
return String.format("%04d%02d%02d%02d%02d%02d.%03d", cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1,
        cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE),
        cal.get(Calendar.SECOND), cal.get(Calendar.MILLISECOND));
DategetCurrentTimeIfCalendareIsNull(Calendar testDate)
Returns the testDate if it has a value otherwise returns the current time.
if (testDate == null) {
    return Calendar.getInstance().getTime();
} else {
    return testDate.getTime();
longgetCurrentTimeLongType(Calendar cal)
get Current Time Long Type
String dateString = String.format("%04d%02d%02d%02d%02d%02d%03d", cal.get(Calendar.YEAR),
        cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.HOUR_OF_DAY),
        cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND), cal.get(Calendar.MILLISECOND));
return Long.valueOf(dateString);
CalendargetCurrentTimeZoneCalendar(String timeZone)
Gets the current time zone calendar.
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone(timeZone));
return calendar;
DategetDateTimeByDate(Date date, int calendarType, int qty)
get Date Time By Date
Calendar now = Calendar.getInstance();
now.setTime(date);
now.set(calendarType, now.get(calendarType) + qty);
return now.getTime();
StringgetFullTimeToString(Calendar argCal)
Return [HH]h[mm]-[ss]-[ms]
Calendar cal = argCal;
if (cal == null) {
    cal = new GregorianCalendar();
String date = getTimeToString(cal) + FULL_TIME_SEPARATOR;
if (cal.get(Calendar.SECOND) < 10) {
    date += "0";
date += cal.get(Calendar.SECOND) + FULL_TIME_SEPARATOR;
if (cal.get(Calendar.MILLISECOND) < 10) {
    date += "0";
if (cal.get(Calendar.MILLISECOND) < 100) {
    date += "0";
date += cal.get(Calendar.MILLISECOND);
return date;
longgetLocalTime(Calendar calendar)
Return the milliseconds passed since 1.1.1970 00:00:00.000 [TimeZone]
return calendar.getTimeInMillis() + calendar.getTimeZone().getOffset(calendar.getTimeInMillis());
CalendargetMaxTimeCalendar(Calendar source)
get Max Time Calendar
Calendar calendar = Calendar.getInstance();
calendar.set(source.get(Calendar.YEAR), source.get(Calendar.MONTH), source.get(Calendar.DAY_OF_MONTH), 23,
        59, 59);
return calendar;
longgetTime(Calendar c)
get Time
return c.getTimeInMillis();