Java Date Format ISO toISO8601(Date date)

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

Description

Formats the given date to a ISO-8601 date/time format, and UTC timezone.

License

Open Source License

Parameter

Parameter Description
date The date to format

Return

The corresponding ISO-8601 formatted string.

Declaration

public static String toISO8601(Date date) 

Method Source Code

//package com.java2s;
/*//  ww w  . ja v  a2  s.  co m
 This file is part of Subsonic.

 Subsonic is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 Subsonic is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with Subsonic.  If not, see <http://www.gnu.org/licenses/>.

 Copyright 2009 (C) Sindre Mehus
 */

import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    private static final DateFormat ISO_8601_DATE_FORMAT = new SimpleDateFormat(
            "yyyy-MM-dd'T'HH:mm:ss");

    /**
     * Formats the given date to a ISO-8601 date/time format, and UTC timezone.
     * <p/>
     * The returned date uses the following format: 2007-12-17T14:57:17
     *
     * @param date The date to format
     * @return The corresponding ISO-8601 formatted string.
     */
    public static String toISO8601(Date date) {
        if (date == null) {
            return null;
        }

        synchronized (ISO_8601_DATE_FORMAT) {
            return ISO_8601_DATE_FORMAT.format(date);
        }
    }
}

Related

  1. toBasicISO8601DateTime(Date value)
  2. toDateIso(Date date)
  3. toISO2616DateFormat(Date date)
  4. toIso8601(@Nullable Calendar calendar)
  5. toIso8601(Date date)
  6. toISO8601(Date date)
  7. toISO8601(Date date)
  8. toISO8601(Date date)
  9. toIso8601(Date dateObj)