Here you can find the source of formatTimestampIso8601(long millis, TimeZone zone)
Parameter | Description |
---|---|
millis | a timestamp in milliseconds. |
zone | a time zone. If null the local timezone is assumed. |
public static String formatTimestampIso8601(long millis, TimeZone zone)
//package com.java2s; /*//from w w w .j a v a 2 s . c o 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.Locale; import java.util.TimeZone; public class Main { /** * Format for ISO 8601 (RFC 3339) date string -- "2012-06-27T12:31:00.003+0000". */ private static final String TIMESTAMP_FORMAT_ISO8601 = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"; /** * Returns a string representation of the specified timestamp value * in the ISO 8601 (RFC 3339) format (e.g. "2012-06-27T12:31:00.003+0000") * in the local time zone. * * @param millis a timestamp in milliseconds. * @return the string representation of the specified timestamp. */ public static String formatTimestampIso8601(long millis) { return formatTimestampIso8601(millis, null); } /** * Returns a string representation of the specified timestamp value * in the ISO 8601 (RFC 3339) format (e.g. "2012-06-27T12:31:00.003+0000") * 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 formatTimestampIso8601(long millis, TimeZone zone) { SimpleDateFormat f = new SimpleDateFormat(TIMESTAMP_FORMAT_ISO8601, Locale.US); f.setTimeZone(zone != null ? zone : TimeZone.getDefault()); return f.format(new Date(millis)); } }