List of utility methods to do Date to UTC Convert
Date | nowUTC() now UTC Date dateTimeNow = new Date(); return localDateToUTC(dateTimeNow); |
Date | localDateToUTC(Date dtLocal) local Date To UTC if (dtLocal == null) return null; TimeZone tz = TimeZone.getDefault(); int currentOffsetFromUTC = tz.getRawOffset() + (tz.inDaylightTime(dtLocal) ? tz.getDSTSavings() : 0); return new Date(dtLocal.getTime() - currentOffsetFromUTC); |
Date | currentDateInUTC() current Date In UTC return new Date(getUTCTimeMillis()); |
Calendar | getCalendarInUTC(String date) get Calendar In UTC Calendar calendar = Calendar.getInstance(TimeZone .getTimeZone("UTC")); SimpleDateFormat fromDateFormat = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss"); calendar.setTime(fromDateFormat.parse(date)); return calendar; |
Date | getDateInUTC(String date) get Date In UTC return getCalendarInUTC(date).getTime();
|