Here you can find the source of formatDateAndTime(int timestamp, String pattern)
Parameter | Description |
---|---|
timestamp | int - Unix timestamp (in seconds). |
pattern | String - Pattern to use to format the date and time. |
public static String formatDateAndTime(int timestamp, String pattern)
//package com.java2s; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; public class Main { public static final long ONE_SECOND = 1000; /**/* w w w . ja va 2 s. com*/ * Formats a Unix timestamp in something human readable. * * @see http://docs.oracle.com/javase/1.4.2/docs/api/java/text/SimpleDateFormat.html * * @param timestamp int - Unix timestamp (in seconds). * @param pattern String - Pattern to use to format the date and time. * * @return Formatted date and time. */ public static String formatDateAndTime(int timestamp, String pattern) { long time = timestamp * ONE_SECOND; Date date = new Date(time); SimpleDateFormat formattedDate = new SimpleDateFormat(pattern, Locale.getDefault()); return formattedDate.format(date); } }