Java Millisecond Format format(long timeMillis, String pattern)

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

Description

format

License

Apache License

Parameter

Parameter Description
timeMillis a parameter
pattern a parameter

Return

String

Declaration

public static String format(long timeMillis, String pattern) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    /**/*from  w ww  . j  a v  a 2s  .c o m*/
     * @param timeMillis
     * @param pattern
     * @return String
     */
    public static String format(long timeMillis, String pattern) {
        if (timeMillis > 0L) {
            DateFormat dateFormat = new SimpleDateFormat(pattern);
            return dateFormat.format(new Date(timeMillis));
        }
        return "";
    }

    /**
     * @param date
     * @param pattern
     * @return String
     */
    public static String format(Date date, String pattern) {
        if (date == null) {
            return "";
        }

        DateFormat dateFormat = new SimpleDateFormat(pattern);
        return dateFormat.format(date);
    }
}

Related

  1. format(long millis)
  2. format(long millis)
  3. format(long millis, String pattern)
  4. format(long milliseconds, String format)
  5. format(long timeMillis)
  6. format_duration(long millis)
  7. formatCcsdsUtcMillisFormat(Date time)
  8. formatDataTimeStamp(final long timeInMillis)
  9. formatElapsedMillis(long time)