Java Date GMT Format getFormattedGMTDate(long timestamp)

Here you can find the source of getFormattedGMTDate(long timestamp)

Description

get Formatted GMT Date

License

Open Source License

Declaration

public static String getFormattedGMTDate(long timestamp) 

Method Source Code


//package com.java2s;
/*//from  w  ww  . j  a  v  a2s  .  co  m
 * Copyright (C) 2012 CyborgDev <cyborg@alta189.com>
 *
 * This file is part of CyborgFactoids
 *
 * CyborgFactoids is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * CyborgFactoids is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

public class Main {
    private static final DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss.SSS z");

    public static String getFormattedGMTDate(long timestamp) {
        Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
        cal.setTimeInMillis(timestamp);
        return formatter.format(cal.getTime());
    }

    public static String getFormattedGMTDate(Date date) {
        Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
        cal.setTime(date);
        return formatter.format(cal.getTime());
    }
}

Related

  1. formatGMT(Date date)
  2. formatGMT(Date date, String parttern)
  3. formatGmtDate(Date date)
  4. formatGMTDate(Date gmtTime, int offset)
  5. getDefaultID2GMT()
  6. getNewGmtSimpleDateFormat(String format)
  7. getStringBaseGMT(Date date, String timezone)
  8. getThreadLocalGMTDateFormat(final String format)
  9. getTimeAndDateAtGMT()