Here you can find the source of formatTimestamp(long millis)
Parameter | Description |
---|---|
millis | a timestamp in milliseconds. |
public static String formatTimestamp(long millis)
//package com.java2s; /*//from w ww.ja va 2 s.co m * Copyright (c) 2015-2016 QuartzDesk.com. * Licensed under the MIT license (https://opensource.org/licenses/MIT). */ import java.text.SimpleDateFormat; import java.util.Date; import java.util.TimeZone; public class Main { private static final String TIMESTAMP_FORMAT_YYYY_MM_DD_HH_MM_SS_SSS = "yyyy-MM-dd HH:mm:ss.SSS"; private static final String WITH_TIME_ZONE = " z"; /** * Returns a string representation of the specified timestamp value * in yyyy-mm-dd hh:mm:ss.SSS format in the local time zone. * * @param millis a timestamp in milliseconds. * @return the string representation of the specified timestamp. */ public static String formatTimestamp(long millis) { SimpleDateFormat f = new SimpleDateFormat(TIMESTAMP_FORMAT_YYYY_MM_DD_HH_MM_SS_SSS); return f.format(new Date(millis)); } /** * Returns a string representation of the specified timestamp value * in yyyy-mm-dd hh:mm:ss.SSS format in the specified time zone. * * @param millis a timestamp in milliseconds. * @param zone a time zone. If null the local timezone is assumed. * @return the string representation of the specified timestamp. */ public static String formatTimestamp(long millis, TimeZone zone) { SimpleDateFormat f = new SimpleDateFormat(TIMESTAMP_FORMAT_YYYY_MM_DD_HH_MM_SS_SSS + WITH_TIME_ZONE); f.setTimeZone(zone != null ? zone : TimeZone.getDefault()); return f.format(new Date(millis)); } }