Java Hour Format format(Date date)

Here you can find the source of format(Date date)

Description

format

License

Open Source License

Parameter

Parameter Description
date a parameter

Return

String

Declaration

public static String format(Date date) 

Method Source Code

//package com.java2s;
/*//from w  w  w .  j a va 2  s  . c  om
 * $RCSfile: GMTUtil.java,v $$
 * $Revision: 1.1  $
 * $Date: 2007-5-29  $
 *
 * Copyright (C) 2008 Skin, Inc. All rights reserved.
 *
 * This software is the proprietary information of Skin, Inc.
 * Use is subject to license terms.
 */

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

public class Main {
    private static String EMPTY = "";
    private static String DATE_FORMAT_GMT = "EEE, dd MMM yyyy HH:mm:ss z";
    private static Locale local = Locale.ENGLISH;
    private static TimeZone timeZone = TimeZone.getTimeZone("GMT");

    /**
     * @param timeMillis
     * @return String
     */
    public static String format(long timeMillis) {
        DateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT_GMT, local);
        dateFormat.setTimeZone(timeZone);
        return dateFormat.format(new Date(timeMillis));
    }

    /**
     * @param date
     * @return String
     */
    public static String format(Date date) {
        DateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT_GMT, local);
        dateFormat.setTimeZone(timeZone);

        return (date != null ? dateFormat.format(date) : EMPTY);
    }
}

Related

  1. format(Date date)
  2. format(Date date)
  3. format(Date date)
  4. format(Date date)
  5. format(Date date)
  6. format(Date date)
  7. format(Date date)
  8. format(Date date)
  9. format(Date date)