Java Timestamp Format toHumanTime(long timestamp, String format)

Here you can find the source of toHumanTime(long timestamp, String format)

Description

Returns a string representation of the timestamp using the specified format.

License

GNU General Public License

Parameter

Parameter Description
timestamp a parameter
format a parameter

Declaration

public static String toHumanTime(long timestamp, String format) 

Method Source Code

//package com.java2s;
/**/*from   w w w. j  a v a  2s .c  o m*/
 * 
 * @author Shinmera
 * @license GPLv3
 * @version 0.0.0
 */

import java.text.SimpleDateFormat;

public class Main {
    public static final SimpleDateFormat defaultSDF = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");

    /**
     * Returns a string representation of the timestamp.
     * @param timestamp
     * @return 
     * @see StringUtils#toHumanTime(long, java.lang.String) 
     */
    public static String toHumanTime(long timestamp) {
        return toHumanTime(timestamp, null);
    }

    /**
     * Returns a string representation of the timestamp using the specified
     * format. The format has to conform to the SimpleDateFormat formatting
     * rules. If the format is set to null, a default time format of 
     * yyyy.MM.dd HH:mm:ss is used.
     * @param timestamp
     * @param format
     * @return 
     * @see SimpleDateFormat#SimpleDateFormat(java.lang.String) 
     */
    public static String toHumanTime(long timestamp, String format) {
        return (format == null) ? defaultSDF.format(timestamp) : new SimpleDateFormat(format).format(timestamp);
    }
}

Related

  1. timestampToFormattedDate(Long timestamp)
  2. timestampToString(final Date ts, final String format, final String tzId)
  3. timestampToString(Long timestamp, String formatStr)
  4. timeToString(long timestamp, SimpleDateFormat format)
  5. toDateFromTimestamp(String timestamp, String format)
  6. toReadableTime(Long timestamp, String format)
  7. toTimeStamp(String dateTime, SimpleDateFormat format, int timeZoneOffset)
  8. unixTimestamp(String date, String dateFormat)