Java Date Format ISO iso8601Date(Date d)

Here you can find the source of iso8601Date(Date d)

Description

Return the ISO8601 string representation of a date.

License

Apache License

Parameter

Parameter Description
d a parameter

Declaration

public static final String iso8601Date(Date d) 

Method Source Code

//package com.java2s;
/**//from w  w w.j a v a 2s.  co m
 * Copyright (C) 2011 University of Washington
 *
 * 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.SimpleDateFormat;
import java.util.Date;

import java.util.TimeZone;

public class Main {
    private static final String PATTERN_ISO8601 = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";

    /**
     * Return the ISO8601 string representation of a date.
     *
     * @param d
     * @return
     */
    public static final String iso8601Date(Date d) {
        if (d == null)
            return null;
        // SDF is not thread-safe
        SimpleDateFormat asGMTiso8601 = new SimpleDateFormat(
                PATTERN_ISO8601); // with
                                  // time
                                  // zone
        asGMTiso8601.setTimeZone(TimeZone.getTimeZone("GMT"));
        return asGMTiso8601.format(d);
    }
}

Related

  1. getJavaISO8601Time(Date date)
  2. getSDFISO8601()
  3. getShortISODateTime(final Date inDate)
  4. iso(Date date)
  5. iso8601(final Date date)
  6. isoDateFormat(Calendar calendar)
  7. isoDateFormat(final Date date)
  8. isoDateTimeUTC(final Date val)
  9. isoFormat(Date date)