Java Long Number to Date formatDateTimeStamp(final long timeInMillis, final String dateFormatString)

Here you can find the source of formatDateTimeStamp(final long timeInMillis, final String dateFormatString)

Description

Formats a date into a given timestamp format.

License

Open Source License

Parameter

Parameter Description
timeInMillis a time in Millis
dateFormatString a time format String

Return

a String timestamp

Declaration

public static String formatDateTimeStamp(final long timeInMillis, final String dateFormatString) 

Method Source Code

//package com.java2s;

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

public class Main {
    /**/*from  w  w w  .  java 2 s .c o  m*/
     * 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. formatDateTime(long d)
  2. formatDateTime(long date)
  3. formatDateTime(long millis)
  4. formatDateTime(long time)
  5. formatDateTime(long timestampEpoch)
  6. formateDate(Long date, String format)
  7. formatEpoch(long date)
  8. formatHttpDate(long d)
  9. formatHTTPDate(long pTime)