Here you can find the source of getJavaISO8601Time(Date date)
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. |
String
that represents the UTC date/time for the specified value using Java's version of the ISO8601 pattern.
public static String getJavaISO8601Time(Date date)
//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); } }