Java Millisecond Format format(long timeMillis)

Here you can find the source of format(long timeMillis)

Description

format

License

Open Source License

Parameter

Parameter Description
timeMillis a parameter

Return

String

Declaration

public static String format(long timeMillis) 

Method Source Code

//package com.java2s;
/*/*from w  w w . ja  va 2 s.co  m*/
 * $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(long millis)
  2. format(long millis)
  3. format(long millis)
  4. format(long millis, String pattern)
  5. format(long milliseconds, String format)
  6. format(long timeMillis, String pattern)
  7. format_duration(long millis)
  8. formatCcsdsUtcMillisFormat(Date time)
  9. formatDataTimeStamp(final long timeInMillis)