Android Utililty Methods Date to UTC Convert

List of utility methods to do Date to UTC Convert

Description

The list of methods to do Date to UTC Convert are organized into topic(s).

Method

DatenowUTC()
now UTC
Date dateTimeNow = new Date();
return localDateToUTC(dateTimeNow);
DatelocalDateToUTC(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);
DatecurrentDateInUTC()
current Date In UTC
return new Date(getUTCTimeMillis());
CalendargetCalendarInUTC(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;
DategetDateInUTC(String date)
get Date In UTC
return getCalendarInUTC(date).getTime();