Java Long Number to Time formatTime(long ms)

Here you can find the source of formatTime(long ms)

Description

format Time

License

Open Source License

Declaration

public static String formatTime(long ms) 

Method Source Code


//package com.java2s;
import java.util.*;

public class Main {
    public static String formatTime(long ms) {
        Date d = new Date(ms);
        Calendar c = new GregorianCalendar();
        c.setTime(d);//from   w  w  w .  j  a v  a2s  .c om
        String hours = String.valueOf(c.get(Calendar.HOUR));
        String minutes = String.format("%02d", c.get(Calendar.MINUTE));
        String seconds = String.format("%02d", c.get(Calendar.SECOND));
        String millis = String.valueOf(c.get(Calendar.MILLISECOND));
        String retval = hours + ":" + minutes + ":" + seconds + "." + millis
                + (c.get(Calendar.AM_PM) == Calendar.AM ? " AM" : " PM");
        return retval;
    }
}

Related

  1. createFileDateTimeString(final Long ms)
  2. elapsedTime(long start, long end)
  3. elapsedTimeToString(long elapsedTime)
  4. formattaData(long date)
  5. formatTime(long date)
  6. formatTimestampLong(long timestamp, String datepattern, TimeZone tz)
  7. formatToUTC(long datetime)
  8. formatXSDateTime(long lastModified)
  9. getAmPm(long time)