List of utility methods to do Calendar Time
void | setTimeToMinOrMax(Calendar cal, boolean max) set Time To Min Or Max if (max) { cal.set(Calendar.HOUR_OF_DAY, 23); cal.set(Calendar.MINUTE, 59); cal.set(Calendar.SECOND, 59); cal.set(Calendar.MILLISECOND, 999); } else { cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); ... |
void | stripTime(final Calendar cal) strip Time cal.clear(Calendar.AM_PM); cal.clear(Calendar.HOUR_OF_DAY); cal.clear(Calendar.HOUR); cal.clear(Calendar.MINUTE); cal.clear(Calendar.SECOND); cal.clear(Calendar.MILLISECOND); |
void | stripTimeComponent(Calendar cal) Strips the time component from a Calendar object, leaving only the date component cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); |
void | time2InicioDelDia(Calendar fecha) time Inicio Del Dia fecha.set(Calendar.HOUR_OF_DAY, 0); fecha.set(Calendar.MINUTE, 0); fecha.set(Calendar.SECOND, 0); fecha.set(Calendar.MILLISECOND, 0); |
Calendar | timestamp17ToCalendar(String timestamp17String) Convert 17-digit date format timestamps (as found in crawl.log, for example) into a GregorianCalendar object. GregorianCalendar calendar = new GregorianCalendar(); int year = Integer.parseInt(timestamp17String.substring(0, 4)); int dayOfMonth = Integer.parseInt(timestamp17String.substring(6, 8)); int month = Integer.parseInt(timestamp17String.substring(4, 6)) - 1; int hourOfDay = Integer.parseInt(timestamp17String.substring(8, 10)); int minute = Integer.parseInt(timestamp17String.substring(10, 12)); int second = Integer.parseInt(timestamp17String.substring(12, 14)); int milliseconds = Integer.parseInt(timestamp17String.substring(14, 17)); ... |
Calendar | timestamp2Calendar(long timestamp) timestamp Calendar Date date = timestamp2Date(timestamp); Calendar cal = Calendar.getInstance(); cal.setTimeZone(TimeZone.getTimeZone("Europe/Brussels")); cal.setTime(date); return cal; |
Calendar | timestampToCalendar(String timestamp) timestamp To Calendar GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC")); int year = Integer.parseInt(timestamp.substring(0, 4)); int month = Integer.parseInt(timestamp.substring(4, 6)) - 1; int day = Integer.parseInt(timestamp.substring(6, 8)); int hour = Integer.parseInt(timestamp.substring(8, 10)); int minute = Integer.parseInt(timestamp.substring(10, 12)); int second = Integer.parseInt(timestamp.substring(12, 14)); calendar.set(year, month, day, hour, minute, second); ... |
Calendar | toDefaultTimeZone(Calendar calendar) to Default Time Zone Calendar c = Calendar.getInstance();
c.setTimeInMillis(calendar.getTimeInMillis());
return c;
|
String | toTimeStamp(Calendar cal) Converts a Calendar object into a timestamp string in ISO 8601 format. if (cal == null) { cal = Calendar.getInstance(); StringBuilder sb = new StringBuilder(); sb.append(String.format("%04d", cal.get(Calendar.YEAR))); sb.append('-').append(String.format("%02d", cal.get(Calendar.MONTH) + 1)); sb.append('-').append(String.format("%02d", cal.get(Calendar.DAY_OF_MONTH))); sb.append('T').append(String.format("%02d", cal.get(Calendar.HOUR_OF_DAY))); ... |
String | toTimeString(final Calendar calendar) Show the Time value of a Calendar as a String. String strHour; String strMinute; String strSecond; strHour = ""; strMinute = ""; strSecond = ""; if (calendar != null) { if (calendar.get(Calendar.HOUR_OF_DAY) < 10) { ... |