Java Millisecond Convert getTime(long time, boolean withMilliseconds)

Here you can find the source of getTime(long time, boolean withMilliseconds)

Description

get Time

License

Apache License

Declaration

public static String getTime(long time, boolean withMilliseconds) throws Exception 

Method Source Code


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

import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
    public static String getTime(long time, boolean withMilliseconds) throws Exception {
        SimpleDateFormat dateFormat = getDateFormat(withMilliseconds);
        return dateFormat.format(new Date(time));
    }/*from  w  ww .  j  a  v  a2s  .c o  m*/

    public static SimpleDateFormat getDateFormat(boolean withMilliseconds) throws Exception {
        if (withMilliseconds) {
            return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
        }
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    }
}

Related

  1. getDurationMillisecond(Date date1, Date date2)
  2. getHumanDisplayForTimediff(Long diffMillis)
  3. getNice(long timeMillisecGMT)
  4. getStringFromMillis(long timestamp)
  5. getTime(long millis)
  6. getTimeByMillis(long now)
  7. getTimeFromMillisAsNICSDate(long timeInMillis)
  8. getTimeInMillisFromNicsDateString(String dateString)
  9. getTimeMillis(String dateStr)