Java Date Format ISO formatTimestampIso8601(long millis, TimeZone zone)

Here you can find the source of formatTimestampIso8601(long millis, TimeZone zone)

Description

Returns a string representation of the specified timestamp value in the ISO 8601 (RFC 3339) format (e.g.

License

MIT License

Parameter

Parameter Description
millis a timestamp in milliseconds.
zone a time zone. If null the local timezone is assumed.

Return

the string representation of the specified timestamp.

Declaration

public static String formatTimestampIso8601(long millis, TimeZone zone) 

Method Source Code

//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));
    }
}

Related

  1. formatIsoDate(Date date)
  2. formatISODate(Date date)
  3. formatISODateTime(Date date)
  4. formatOneDecimal(int iNumber, int iDivisor)
  5. formattedIso8601DateString(Calendar pCal)
  6. formatToIso8601(Date d)
  7. formatToISO8601(Date date)
  8. formatWikiISO8601(Date d)
  9. fromIso8601(@Nullable String date)