Java Millisecond Format timeMillisToString(long timeMillis, String dateFormat)

Here you can find the source of timeMillisToString(long timeMillis, String dateFormat)

Description

time Millis To String

License

Open Source License

Declaration

public static String timeMillisToString(long timeMillis, String dateFormat) 

Method Source Code


//package com.java2s;
/*/*from   w  ww . j  a v a2 s. co m*/
 * Title:      TRS ??????
 * Copyright: Copyright (c) 2004-2005, TRS?????????????. All rights reserved.
 * License:   see the license file.
 * Company:   TRS?????????????(www.trs.com.cn)
 * 
 * Created on 2005-5-11
 */

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {

    public static String timeMillisToString(long timeMillis) {
        return timeMillisToString(timeMillis, "yyyy-MM-dd HH:mm:ss");
    }

    public static String timeMillisToString(long timeMillis, String dateFormat) {
        if ("".equals(dateFormat) || dateFormat == null) {
            return null;
        }
        try {
            return new SimpleDateFormat(dateFormat).format(new Date(timeMillis));
        } catch (Exception e) {
            return null;
        }
    }
}

Related

  1. printDate(long millis)
  2. reverseFormattedDateWithMilliseconds()
  3. stringToTimestampInMilliseconds(String s, DateFormat formatter)
  4. strToDateMillisTimestamp(String dateStr, String formatStr)
  5. timeFormat(final long milliseconds)