Java Date GMT Format toGMTString(Date d)

Here you can find the source of toGMTString(Date d)

Description

Returns a string representation of the given Date object of the form: d MMM yyyy hh:mm:ss GMT

License

Open Source License

Parameter

Parameter Description
d the date.

Return

the GMT string representation of the given date.

Declaration

public static String toGMTString(Date d) 

Method Source Code


//package com.java2s;
/* //  w ww.  j  ava  2 s .c o m
 * Copyright(c) 2005 Center for E-Commerce Infrastructure Development, The
 * University of Hong Kong (HKU). All Rights Reserved.
 *
 * This software is licensed under the GNU GENERAL PUBLIC LICENSE Version 2.0 [1]
 * 
 * [1] http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
 */

import java.text.SimpleDateFormat;
import java.util.*;

public class Main {
    /**
     * Returns a string representation of the given Date object of the form: 
     * d MMM yyyy hh:mm:ss GMT
     * 
     * @param d the date.
     * @return the GMT string representation of the given date.
     */
    public static String toGMTString(Date d) {
        SimpleDateFormat formatter = new SimpleDateFormat("d MMM yyyy HH:mm:ss z", Locale.US);
        formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
        return formatter.format(d);
    }
}

Related

  1. parseDate(String gmtTimeString)
  2. parseGMT(String gmtTime)
  3. parseGMTDatetime(String str)
  4. parseGMTTime(Long time, String format)
  5. timeStampGMT(Date date)
  6. toGMTString(Date dtIn)
  7. toStringWithoutGMT(Date date)