Java Timestamp Format formatToString(long timestamp, String datePattern)

Here you can find the source of formatToString(long timestamp, String datePattern)

Description

Take a timestamp, and turn it into a string with the specified format.

License

Apache License

Parameter

Parameter Description
timestamp the given unix timestamp
datePattern the date pattern (for example "dd-MM-yyyy HH:mm:ss")

Return

the formatted date as a string

Declaration

public static String formatToString(long timestamp, String datePattern) 

Method Source Code


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

import java.sql.Timestamp;

import java.time.format.DateTimeFormatter;

public class Main {
    /**/*from   www.  j a  v a 2 s. c  o  m*/
     * Take a timestamp, and turn it into a string with the specified format.
     * @param timestamp the given unix timestamp
     * @param datePattern the date pattern (for example "dd-MM-yyyy HH:mm:ss")
     * @return the formatted date as a string
     */
    public static String formatToString(long timestamp, String datePattern) {
        return (new Timestamp(timestamp * 1000).toLocalDateTime()).format(DateTimeFormatter.ofPattern(datePattern));
    }
}

Related

  1. formatTimestampToIndex(java.sql.Timestamp timestamp)
  2. formatTimestampToLong(final String timestampStr)
  3. formatTimestampWithSlashes( java.sql.Timestamp tsZeitpunkt)
  4. formatTimeToString(long timestamp)
  5. formatToLong(String format)
  6. formatValue(Object obj, boolean isboolean)
  7. friendlyTimestamp(Date date)
  8. friendlyTimestampFormat()
  9. friendlyTimestampFormat()