List of utility methods to do UTC Date
Date | toUTCDate(String dateStr) to UTC Date SimpleDateFormat format = new SimpleDateFormat(DATE_TIME_FORMAT, Locale.ENGLISH); format.setTimeZone(TimeZone.getTimeZone(TIME_ZONE_UTC_GMT)); return format.parse(dateStr); |
String | toUTCString(Date date) Converts a date to a UTC String representation SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z"); sd.setTimeZone(TimeZone.getTimeZone("GMT")); return sd.format(date); |
String | toUTCString(long t) to UTC String if (format == null) { format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); format.setTimeZone(TimeZone.getTimeZone("UTC")); return format.format(new Date(t)); |
DateFormat | utcTime(Locale locale) utc Time DateFormat format = DateFormat.getTimeInstance(DateFormat.MEDIUM, locale); format.setTimeZone(TimeZone.getTimeZone("UTC")); return format; |
String | utcTimestamp(Date date) utc Timestamp return UTF_DATE_FORMAT.format(date);
|
String | utcTimeToString(String dateStr) utc Time To String SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT_DEFAULT); String time = ""; try { Date date = format.parse(dateStr); time = toStringFromDate(date, null); } catch (ParseException e) { e.printStackTrace(); return time; |
Date | utcToDate(String utcTimestamp) utc To Date SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); df.setTimeZone(TimeZone.getTimeZone("GMT")); Date d = df.parse(utcTimestamp.replaceFirst("Z$", "+0000")); return d; |
String | utcToLocal(Date date) Utc to local string. try { SimpleDateFormat sdf = new SimpleDateFormat(UTC_FORMAT); sdf.applyPattern(DEFAULT_FORMAT); return sdf.format(date); } catch (Exception e) { e.printStackTrace(); return null; |
String | utcTolocal(String utc) utc Tolocal if (utc == null) return "NULL"; DateFormat utcFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); utcFormat.setTimeZone(TimeZone.getTimeZone("UTC")); Date date = null; try { date = utcFormat.parse(utc); } catch (ParseException e) { ... |