Here you can find the source of formatToString(long timestamp, String datePattern)
Parameter | Description |
---|---|
timestamp | the given unix timestamp |
datePattern | the date pattern (for example "dd-MM-yyyy HH:mm:ss") |
public static String formatToString(long timestamp, String datePattern)
//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)); } }