Java Date Format ISO getJavaISO8601Time(Date date)

Here you can find the source of getJavaISO8601Time(Date date)

Description

Returns the UTC date/time String for the specified value using Java's version of the ISO8601 pattern, which is limited to millisecond precision.

License

Apache License

Parameter

Parameter Description
date A <code>Date</code> object that represents the date to convert to UTC date/time in Java's version of the ISO8601 pattern.

Return

A String that represents the UTC date/time for the specified value using Java's version of the ISO8601 pattern.

Declaration

public static String getJavaISO8601Time(Date date) 

Method Source Code

//package com.java2s;
/**// www .  j  a  v a  2 s. co  m
 * Copyright Microsoft Corporation
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.Locale;

import java.util.TimeZone;

public class Main {
    /**
     * Stores a reference to the UTC time zone.
     */
    public static final TimeZone UTC_ZONE = TimeZone.getTimeZone("UTC");
    /**
     * Stores a reference to the US locale.
     */
    public static final Locale LOCALE_US = Locale.US;
    /**
     * Stores a reference to the Java version of ISO8601_LONG date/time pattern.  The full version cannot be used
     * because Java Dates have millisecond precision.
     */
    private static final String JAVA_ISO8601_PATTERN = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";

    /**
     * Returns the UTC date/time String for the specified value using Java's version of the ISO8601 pattern,
     * which is limited to millisecond precision.
     * 
     * @param date
     *            A <code>Date</code> object that represents the date to convert to UTC date/time in Java's version
     *            of the ISO8601 pattern.
     * 
     * @return A <code>String</code> that represents the UTC date/time for the specified value using Java's version
     *            of the ISO8601 pattern.
     */
    public static String getJavaISO8601Time(Date date) {
        final DateFormat formatter = new SimpleDateFormat(JAVA_ISO8601_PATTERN, LOCALE_US);
        formatter.setTimeZone(UTC_ZONE);
        return formatter.format(date);
    }
}

Related

  1. getISOFormat(java.util.Date date)
  2. getISOFromMillisec(long timeMillisecGMT)
  3. getISOHttpDateFormat()
  4. getIsoTimeStamp()
  5. getIsoTimestampFormatter()
  6. getSDFISO8601()
  7. getShortISODateTime(final Date inDate)
  8. iso(Date date)
  9. iso8601(final Date date)