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

StringgetUTCDate()
get UTC Date
SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy hh:mm");
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
return sdf.format(cal.getTime());
StringgetUtcDate(String date, String pattern)
get Utc Date
try {
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    Date now = Calendar.getInstance().getTime();
    Date theDate = format.parse(date);
    theDate.setHours(now.getHours());
    theDate.setMinutes(now.getMinutes());
    format.setTimeZone(TimeZone.getTimeZone("UTC"));
    format.applyPattern(pattern);
...
DategetUTCDateFromString(String date)
get UTC Date From String
DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss", Locale.ENGLISH);
Date result = df.parse(date);
return getUTCDate(result.getTime());
StringgetUtcDateString()
get Utc Date String
Date curDate = new Date();
SimpleDateFormat format = new SimpleDateFormat(UTC_DATE_FORMAT);
return format.format(curDate);
StringgetUtcDateStringFromTimestamp(Date timeStamp)
Convert timestamp to UTC format date string.
DateFormat df = new SimpleDateFormat(UTC_DATE_FORMAT);
df.setTimeZone(TimeZone.getTimeZone("GMT"));
return df.format(timeStamp);
StringGetUTCdatetimeAsString()
Get UT Cdatetime As String
String DATEFORMAT = "yyyy-MM-dd HH:mm:ss";
final SimpleDateFormat sdf = new SimpleDateFormat(DATEFORMAT);
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
final String utcTime = sdf.format(new Date());
return utcTime;
StringGetUtcNow()
Get Utc Now
return FormatAsUtc(new Date());
StringgetUTCTime()
get UTC Time
SimpleDateFormat formatter = (SimpleDateFormat) DateFormat.getDateTimeInstance(DateFormat.MONTH_FIELD,
        DateFormat.LONG, Locale.US);
formatter.setTimeZone(TimeZone.getTimeZone(TIME_ZONE_GMT));
formatter.applyPattern(EEE_DD_MMM_YYYY_HH_MM_SS_Z_FORMAT);
return formatter.format(new Date());
StringgetUTCTime()
Returns current time in UTC timezone as string
Date currentTime = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("EEE, MMM d, yyyy hh:mm:ss a z");
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
return sdf.format(currentTime);
StringgetUTCTime(final Date inDate)
Returns the UTC date/time for the specified value using the RFC1123 pattern.
final DateFormat rfc1123Format = new SimpleDateFormat(RFC1123_PATTERN, LOCALE_US);
rfc1123Format.setTimeZone(UTC_ZONE);
return rfc1123Format.format(inDate);