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

DatetoUTCDate(String dateStr)
to UTC Date
SimpleDateFormat format = new SimpleDateFormat(DATE_TIME_FORMAT, Locale.ENGLISH);
format.setTimeZone(TimeZone.getTimeZone(TIME_ZONE_UTC_GMT));
return format.parse(dateStr);
StringtoUTCString(Date date)
Converts a date to a UTC String representation
SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
sd.setTimeZone(TimeZone.getTimeZone("GMT"));
return sd.format(date);
StringtoUTCString(long t)
to UTC String
if (format == null) {
    format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    format.setTimeZone(TimeZone.getTimeZone("UTC"));
return format.format(new Date(t));
DateFormatutcTime(Locale locale)
utc Time
DateFormat format = DateFormat.getTimeInstance(DateFormat.MEDIUM, locale);
format.setTimeZone(TimeZone.getTimeZone("UTC"));
return format;
StringutcTimestamp(Date date)
utc Timestamp
return UTF_DATE_FORMAT.format(date);
StringutcTimeToString(String dateStr)
utc Time To String
SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT_DEFAULT);
String time = "";
try {
    Date date = format.parse(dateStr);
    time = toStringFromDate(date, null);
} catch (ParseException e) {
    e.printStackTrace();
return time;
DateutcToDate(String utcTimestamp)
utc To Date
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
df.setTimeZone(TimeZone.getTimeZone("GMT"));
Date d = df.parse(utcTimestamp.replaceFirst("Z$", "+0000"));
return d;
StringutcToLocal(Date date)
Utc to local string.
try {
    SimpleDateFormat sdf = new SimpleDateFormat(UTC_FORMAT);
    sdf.applyPattern(DEFAULT_FORMAT);
    return sdf.format(date);
} catch (Exception e) {
    e.printStackTrace();
    return null;
StringutcTolocal(String utc)
utc Tolocal
if (utc == null)
    return "NULL";
DateFormat utcFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
utcFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
Date date = null;
try {
    date = utcFormat.parse(utc);
} catch (ParseException e) {
...