Java Utililty Methods Date GMT Format

List of utility methods to do Date GMT Format

Description

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

Method

StringgetTimeAndDateAtGMT()
This method returns the current time in GMT.
String pattern = "MMMMM dd, yyyy; H:mm";
SimpleDateFormat simpleformat = new SimpleDateFormat(pattern);
TimeZone tz = TimeZone.getTimeZone("GMT");
java.util.Calendar cal = Calendar.getInstance(tz);
simpleformat.setCalendar(cal);
String date = simpleformat.format(new Date());
return date + " GMT";
StringgetTzToGmt(String dateStr, String dateFormat, String beforeTimeZone, String afterTimeZone)
get Tz To Gmt
SimpleDateFormat sdfBefore = new SimpleDateFormat(dateFormat);
sdfBefore.setTimeZone(TimeZone.getTimeZone(beforeTimeZone));
SimpleDateFormat sdfAfter = new SimpleDateFormat(dateFormat);
sdfAfter.setTimeZone(TimeZone.getTimeZone(afterTimeZone));
Date date = stringToDate(dateStr, sdfBefore);
String dateGmtEight = sdfAfter.format(date);
return dateGmtEight;
DateparseDate(String gmtTimeString)
parse Date
try {
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    df.setTimeZone(java.util.TimeZone.getTimeZone("GMT"));
    Date date = df.parse(gmtTimeString);
    return date;
} catch (ParseException e) {
    throw new RuntimeException("convrt to runtime exception", e);
DateparseGMT(String gmtTime)
parse GMT
GMT_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT"));
return GMT_FORMAT.parse(gmtTime);
DateparseGMTDatetime(String str)
parse GMT Datetime
SimpleDateFormat sdf = getGMTDatetimeFormat();
return sdf.parse(str);
StringparseGMTTime(Long time, String format)
parse GMT Time
Date date = new Date();
date.setTime(time);
SimpleDateFormat dformat = getDateParser(format);
return dformat.format(date);
StringtimeStampGMT(Date date)
Creates a formatted timestamp string of the given date in GMT.
return timeStamp(date, GMT);
StringtoGMTString(Date d)
Returns a string representation of the given Date object of the form: d MMM yyyy hh:mm:ss GMT
SimpleDateFormat formatter = new SimpleDateFormat("d MMM yyyy HH:mm:ss z", Locale.US);
formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
return formatter.format(d);
StringtoGMTString(Date dtIn)
Convert a date into a format suitable for http headers etc "EEE, dd MMM yyyy HH:mm:ss z"
if (dtIn == null)
    dtIn = new Date();
String sGMTFormat = "EEE, dd MMM yyyy HH:mm:ss z";
return formatDate(dtIn, sGMTFormat, Locale.UK, TimeZone.getTimeZone("GMT"));
StringtoStringWithoutGMT(Date date)
to String Without GMT
return toStringWithoutGMT(date, null);