Java Utililty Methods Date UTC Parse

List of utility methods to do Date UTC Parse

Description

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

Method

CalendargetDateTimeUTC(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.DategetLocalTimeFromUTC(String localTimeZoneId, java.util.Date utcTimestamp)
getLocal: returns the local time.
java.util.TimeZone tz = getTimeZone(localTimeZoneId);
return getLocalTimeFromUTC(tz, utcTimestamp);
java.util.DategetUTC(java.util.Date siteTimestamp)
getUTC: returns the UTC time.
return getUTC(java.util.Locale.GERMANY, siteTimestamp);
DategetUTCDate()
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) {
...
DategetUTCDate()
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();
DategetUTCDate()
get UTC Date
Calendar c = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
return c.getTime();
DategetUTCDate(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();
DategetUtcDate(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;
...
DategetUtcDate(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;
DategetUTCDate(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();