Java Millisecond Format formatDataTimeStamp(final long timeInMillis)

Here you can find the source of formatDataTimeStamp(final long timeInMillis)

Description

Formats a date into a standard timestamp format: yy-MM-dd HH:mm:ss.SSS

License

Open Source License

Parameter

Parameter Description
timeInMillis a time in Millis

Return

a String timestamp

Declaration

public static String formatDataTimeStamp(final long timeInMillis) 

Method Source Code

//package com.java2s;

import java.text.SimpleDateFormat;
import java.util.Calendar;

public class Main {
    /**/* w  w w.  j  a  v  a2s .  c  o  m*/
     * Formats a date into a standard timestamp format: yy-MM-dd HH:mm:ss.SSS
     * 
     * @param timeInMillis
     *            a time in Millis
     * @return a String timestamp
     */
    public static String formatDataTimeStamp(final long timeInMillis) {
        final String timeFormat = "yy-MM-dd HH:mm:ss.SSS";
        return formatDateTimeStamp(timeInMillis, timeFormat);
    }

    /**
     * Formats a date into a given timestamp format.
     * 
     * @param timeInMillis
     *            a time in Millis
     * @param dateFormatString
     *            a time format String
     * @return a String timestamp
     */
    public static String formatDateTimeStamp(final long timeInMillis, final String dateFormatString) {
        String tmpString = "";

        // Convert the timeInMillis to Date
        Calendar cal = Calendar.getInstance();
        cal.setTimeInMillis(timeInMillis);
        java.util.Date date = cal.getTime();

        // Format it
        SimpleDateFormat format = new SimpleDateFormat(dateFormatString);
        tmpString = format.format(date);

        return tmpString;
    }
}

Related

  1. format(long milliseconds, String format)
  2. format(long timeMillis)
  3. format(long timeMillis, String pattern)
  4. format_duration(long millis)
  5. formatCcsdsUtcMillisFormat(Date time)
  6. formatElapsedMillis(long time)
  7. formatElapsedTime(long millis)
  8. formateTime(long milliseconds)
  9. formatMillis(int millis, int digits)