Java Utililty Methods Date UTC Format

List of utility methods to do Date UTC Format

Description

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

Method

DateFormatcreateUTCDateFormatter(String dateFormat)
Creates a DateFormat that assumes the incoming date is in UTC time.
DateFormat formatter = new SimpleDateFormat(dateFormat);
formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
return formatter;
StringFormatAsUtc(Date date)
Format As Utc
SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
f.setTimeZone(TimeZone.getTimeZone("UTC"));
return f.format(date);
StringformatAsUTC(java.util.Date date, String pattern)
format: returns the formatted date as String.
if (date != null) {
    SimpleDateFormat sdf = new SimpleDateFormat(pattern);
    sdf.setTimeZone(getUTCTimeZone());
    return sdf.format(date);
} else {
    return null;
StringformatDate(Date date, String pattern, boolean toUTC)
Format date to string using specified pattern.
DateFormat df = new SimpleDateFormat(pattern);
if (toUTC) {
    TimeZone tz = TimeZone.getTimeZone("UTC");
    df.setTimeZone(tz);
return df.format(date);
StringformatTimeStamp(byte[] btValue, int iOffset, int iLength, int iUtcOffset)
format Time Stamp
if ((btValue.length < iOffset + iLength) || (iLength < 9))
    return "";
Date dtReturn = null;
long lOffset = 0;
if (btValue[iOffset + 2] == '+' || btValue[iOffset + 2] == '-') {
    dtReturn = new Date(getBCDValue(btValue[iOffset + 8]), getBCDValue(btValue[iOffset + 7]) - 1,
            getBCDValue(btValue[iOffset + 6]), getBCDValue(btValue[iOffset + 5]),
            getBCDValue(btValue[iOffset + 4]), getBCDValue(btValue[iOffset + 3]));
...
StringformatUTC(Date date, String format)
format UTC
SimpleDateFormat sdf = new SimpleDateFormat(format);
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
return sdf.format(date);
StringformatUtcDateIfNotNull(final Date date)
format Utc Date If Not Null
if (null == date) {
    return null;
final SimpleDateFormat dateFormat = new SimpleDateFormat(ISO8601_DATE_FORMAT_PATTERN);
dateFormat.setTimeZone(TimeZone.getTimeZone(UTC));
String formattedDate;
formattedDate = dateFormat.format(date);
return formattedDate;
...
StringformatUtcTime(long tval)
format Utc Time
SimpleDateFormat utcSdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
utcSdf.setTimeZone(new SimpleTimeZone(0, "UTC"));
String stg = utcSdf.format(tval);
return stg;
StringgetStrTimeByUTC(long utc, String format)
get Str Time By UTC
return new SimpleDateFormat(format).format(new Date(utc));
SimpleDateFormatgetUTCDateFormat()
get UTC Date Format
SimpleDateFormat iso8601DateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
iso8601DateFormat.setTimeZone(TimeZone.getTimeZone(UTC_STR));
return iso8601DateFormat;