Java Long Number to Timestamp timestampToString(long timestamp)

Here you can find the source of timestampToString(long timestamp)

Description

Convert a timestamp in a readable format for a human in the format : YYYY/mm/dd HH:mm:ss

License

Apache License

Parameter

Parameter Description
timestamp the timestamp to be converted.

Return

the human friendly date as mentioned in the description.

Declaration

public static String timestampToString(long timestamp) 

Method Source Code

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

import java.text.SimpleDateFormat;

import java.util.Calendar;
import java.util.GregorianCalendar;

public class Main {
    /**/* w  ww . j a  v a  2  s. c o m*/
     * Convert a timestamp in a readable format for a human in the format : YYYY/mm/dd HH:mm:ss
     * @param timestamp the timestamp to be converted.
     * @return the human friendly date as mentioned in the description.
     */
    public static String timestampToString(long timestamp) {
        Calendar cal = GregorianCalendar.getInstance();
        timestamp *= 1000;
        cal.setTimeInMillis(timestamp);
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
        return cal.get(GregorianCalendar.YEAR) + "-" + (cal.get(GregorianCalendar.MONTH) + 1) + "-"
                + cal.get(GregorianCalendar.DAY_OF_MONTH) + " " + sdf.format(cal.getTime());
    }
}

Related

  1. timestamp2Date(long timestamp, String timezone)
  2. timestamp2DateTime(long t)
  3. timestampToHumanDateAndTime(long timestamp)
  4. timestampToString(long micros)
  5. timestampToString(long time)
  6. timeString(long timestamp)
  7. toDateTimeString(long timestamp)
  8. toSolrTimestamp(Long epoch)
  9. unixTimestampToDate(long timestamp)