List of utility methods to do Date UTC Parse
Calendar | getDateTimeUTC(int year, int month, int day, int hour, int minute, int second) get Date Time UTC Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); cal.clear(); cal.set(year, month, day, hour, minute, second); return cal; |
java.util.Date | getLocalTimeFromUTC(String localTimeZoneId, java.util.Date utcTimestamp) getLocal: returns the local time. java.util.TimeZone tz = getTimeZone(localTimeZoneId);
return getLocalTimeFromUTC(tz, utcTimestamp);
|
java.util.Date | getUTC(java.util.Date siteTimestamp) getUTC: returns the UTC time. return getUTC(java.util.Locale.GERMANY, siteTimestamp);
|
Date | getUTCDate() get UTC Date try { Calendar local = Calendar.getInstance(); int offset = local.getTimeZone().getOffset(local.getTimeInMillis()); GregorianCalendar utc = new GregorianCalendar(gmtTimeZone); utc.setTimeInMillis(local.getTimeInMillis()); utc.add(Calendar.MILLISECOND, -offset); return utc.getTime(); } catch (Exception ex) { ... |
Date | getUTCDate() get UTC Date Calendar local = Calendar.getInstance(); int offset = local.getTimeZone().getOffset(local.getTimeInMillis()); GregorianCalendar utc = new GregorianCalendar(gmtTimeZone); utc.setTimeInMillis(local.getTimeInMillis()); utc.add(Calendar.MILLISECOND, -offset); return utc.getTime(); |
Date | getUTCDate() get UTC Date Calendar c = new GregorianCalendar(TimeZone.getTimeZone("UTC")); return c.getTime(); |
Date | getUTCDate(Date date) Converts local time to UTC time properly Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(date.getTime() - cal.getTimeZone().getOffset(date.getTime()));
return cal.getTime();
|
Date | getUtcDate(Date date) get Utc Date Calendar calendar = Calendar.getInstance(); calendar.setTime(date); TimeZone z = calendar.getTimeZone(); int offset = z.getRawOffset(); if (z.inDaylightTime(new Date())) { offset = offset + z.getDSTSavings(); int offsetHrs = offset / 1000 / 60 / 60; ... |
Date | getUtcDate(final int year, final int month, final int day) This method returns an UTC date base on the year, the month and the day. final Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC")); calendar.set(year, month, day, 0, 0, 0); final Date date = calendar.getTime(); return date; |
Date | getUTCDate(int year, int month, int date, int h, int m, int s, int milli) Retuns a UTC date. GregorianCalendar c = new GregorianCalendar(TimeZone.getTimeZone("UTC")); c.set(year, month, date, h, m, s); c.set(Calendar.MILLISECOND, milli); return c.getTime(); |