Java Time in GMT getGmtTimeString(double startTime)

Here you can find the source of getGmtTimeString(double startTime)

Description

Returns a time string of the form yyyy-MM-dd'T'HH:mm:ss'Z' from the specified date number.

License

Open Source License

Parameter

Parameter Description
startTime The long date number.

Declaration

public static String getGmtTimeString(double startTime) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.text.SimpleDateFormat;
import java.util.Date;

import java.util.TimeZone;

public class Main {
    /** String used for non-available data */
    private static final String NOT_AVAILABLE = "NA";

    /**/*w w w .  j  a v a2  s  .c om*/
     * Returns a time string of the form yyyy-MM-dd'T'HH:mm:ss'Z' from the
     * specified date number. If the input is null, then the value of
     * NOT_AVAILABLE is returned. The string represents GMT time.
     * 
     * @param startTime The long date number.
     * @return
     * @see #NOT_AVAILABLE
     */
    public static String getGmtTimeString(double startTime) {
        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);
    }
}

Related

  1. getGMTString(Date d)
  2. getGMTString(Date date, TimeZone tz)
  3. getGMTTime(Date localTime)
  4. getGMTTime(final Date date)
  5. getGMTTimeStr(Date pageTime, int offset)