Java Utililty Methods Time in GMT

List of utility methods to do Time in GMT

Description

The list of methods to do Time in GMT are organized into topic(s).

Method

StringgetGmtFromTimeInMillis(String val)
Gets the gmt from time in millis.
long time = Long.parseLong(val);
DateFormat gmtFormat = new SimpleDateFormat("E, dd-MMM-yyyy hh:mm:ss");
TimeZone gmtTime = TimeZone.getTimeZone("GMT");
gmtFormat.setTimeZone(gmtTime);
return (gmtFormat.format(new Date(time)) + " GMT");
StringgetGMTime()
Get the current GMT time for user notification.
SimpleDateFormat gmtDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
gmtDateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
return gmtDateFormat.format(new java.util.Date());
StringgetGMTime()
get GM Time
SimpleDateFormat dform = ((SimpleDateFormat) DateFormat.getDateInstance());
dform.applyPattern("yyyyMMddHH");
dform.setTimeZone(TimeZone.getTimeZone("GMT"));
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
String gmtime = dform.format(cal.getTime());
gmtime += Integer.toString(((int) Math.floor((double) cal.get(Calendar.MINUTE) / 10)));
return gmtime;
StringgetGMTString(Date d)
get GMT String
DateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.ENGLISH);
format.setTimeZone(TimeZone.getTimeZone("GMT"));
return format.format(d);
StringgetGMTString(Date date, TimeZone tz)
get GMT String
DecimalFormat fmt = new DecimalFormat("'GMT'+00':00';'GMT'-00':00'");
int off = tz.getRawOffset();
if (tz.inDaylightTime(date))
    off += 3600000;
off = off / 3600000;
return fmt.format(off);
DategetGMTTime(Date localTime)
get GMT Time from local time.
if (localTime == null)
    return null;
return getTime(localTime, TimeZone.getDefault(), TimeZone.getTimeZone("GMT"));
StringgetGMTTime(final Date date)
Returns the GTM date/time String for the specified value using the RFC1123 pattern.
final DateFormat formatter = new SimpleDateFormat(RFC1123_PATTERN, LOCALE_US);
formatter.setTimeZone(GMT_ZONE);
return formatter.format(date);
StringgetGMTTimeStr(Date pageTime, int offset)
get GMT Time string for given page date and offset, time would be formated to DEFAULT_DATE_FORMAT;
return formatDate(getGMTFromLocal(pageTime, offset), DEFAULT_DATE_FORMAT);
StringgetGmtTimeString(double startTime)
Returns a time string of the form yyyy-MM-dd'T'HH:mm:ss'Z' from the specified date number.
if (Double.isNaN(startTime)) {
    return NOT_AVAILABLE;
Date date = new Date(Math.round(startTime));
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
return formatter.format(date);