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

voidresetTime(GregorianCalendar cal)
Sets the time in the given cal to 00:00:00.000
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
longroundTime(double dt, Calendar tmp)
round Time
long t = toLongTime(dt);
tmp.setTimeInMillis(t);
int sec = tmp.get(Calendar.SECOND);
return (sec > 30) ? t + (60 - sec) : t - sec;
booleansameTime(Calendar one, Calendar two)
Returns true if the two given calendars are dated on the same time.
return one.getTimeInMillis() == two.getTimeInMillis();
voidsetDateTimeByString(Calendar theDateTime, String str)
set the calendar value of theDateTime according to a string like "2008-08-08T08:08:08"
str = str.trim();
String year, month, day;
int i1, i2, iT;
i1 = str.indexOf("-");
i2 = str.indexOf("-", i1 + 1);
iT = str.indexOf('T');
year = str.substring(0, i1);
month = str.substring(i1 + 1, i2);
...
voidsetTime(Calendar cal, int h, int m, int s, int ms)
set Time
cal.set(Calendar.HOUR_OF_DAY, h);
cal.set(Calendar.MINUTE, m);
cal.set(Calendar.SECOND, s);
cal.set(Calendar.MILLISECOND, ms);
voidsetTime(Calendar cal, String time)
set Time
int hour = 0;
int minute = 0;
int idx = time.indexOf(':');
if (idx < 0) {
    hour = Integer.parseInt(time);
} else {
    hour = Integer.parseInt(time.substring(0, idx));
    time = time.substring(idx + 1);
...
CalendarsetTime(final Calendar calendat, final String[] test)
set Time
if (test.length == 3) {
    calendat.set(Calendar.HOUR_OF_DAY, Integer.parseInt(test[0].trim()));
    calendat.set(Calendar.MINUTE, Integer.parseInt(test[1].trim()));
    calendat.set(Calendar.SECOND, Integer.parseInt(test[2].trim()));
if (test.length == 2) {
    calendat.set(Calendar.HOUR_OF_DAY, Integer.parseInt(test[0].trim()));
    calendat.set(Calendar.MINUTE, Integer.parseInt(test[1].trim()));
...
voidsetTimeFrom(Calendar c)
set Time From
c.set(Calendar.HOUR_OF_DAY, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
voidsetTimeTo0(final Calendar calendar)
set Time To
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
voidsetTimeToMidnight(GregorianCalendar c)
Sets the time fields (24-hour, minute, second, millisecond) of the specified GregorianCalendar instance to 0 so it subsequently represents midnight of the same day as before.
c.set(Calendar.HOUR_OF_DAY, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);