Java Utililty Methods UTC Date

List of utility methods to do UTC Date

Description

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

Method

StringgetUtcTimestamp()
get Utc Timestamp
DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
format.setTimeZone(TimeZone.getTimeZone("GMT"));
return format.format(new Date());
StringgetUtcTimestamp()
Request timestamp in ISO 8601 combined date and time in UTC.
SimpleDateFormat timeFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
timeFormatter.setTimeZone(new SimpleTimeZone(SimpleTimeZone.UTC_TIME, "UTC"));
return timeFormatter.format(new Date());
StringgetUTCTimestamp(Date date)
get UTC Timestamp
return TS_FORMAT.format(date);
StringgetUtcTimestampAsString(Date date)
Returns an ISO 8601 timestamp for the given date.
DateFormat dfm = new SimpleDateFormat(DATE_FORMAT);
dfm.setTimeZone(TimeZone.getTimeZone(UTC_TIMEZONE));
return dfm.format(date);
StringgetUTCTimeString4Digits(Date date)
get UTC Time String Digits
SimpleDateFormat sdf = new SimpleDateFormat("HHmm");
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
return sdf.format(date);
StringnowInUTC()
Get the current time in UTC
Date date = new Date();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
df.setTimeZone(TimeZone.getTimeZone("GMT"));
return df.format(date);
StringnowUtc(String pattern)
Returns the current system date as string with the specified format
final SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
return dateFormat.format(now());
StringnowUTCString()
now UTC String
try {
    DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
    return formatter.format(nowUTC());
} catch (Exception e) { 
    return null;
StringSerializeUtc(Date dt)
Serialize Utc
Calendar c = new GregorianCalendar(UTC, Locale.US);
c.setTime(dt);
StringBuilder b = new StringBuilder(21);
b.append(pad0s(c.get(Calendar.YEAR), 4));
b.append("-");
b.append(pad0s(c.get(Calendar.MONTH) + 1, 2));
b.append("-");
b.append(pad0s(c.get(Calendar.DAY_OF_MONTH), 2));
...
DatestringToUTC(String utc)
Converts a UTC date/time string to a UTC date/time value.
return ISO_8601_FORMAT.parse(utc);