Java Date Format ISO formatISO8601Date(Date date)

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

Description

format ISO Date

License

Apache License

Declaration

public static String formatISO8601Date(Date date) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.Date;
import java.util.TimeZone;

public class Main {
    public static final TimeZone GMT_TIMEZONE = TimeZone.getTimeZone("GMT");
    public static final String ISO8601DATE_WITH_MILLS_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
    public static final String ISO8601DATE_WITH_MILLS_TIMEZONE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";

    public static String formatISO8601Date(Date date) {
        DateFormat format = new SimpleDateFormat(ISO8601DATE_WITH_MILLS_FORMAT);
        format.setTimeZone(GMT_TIMEZONE);
        return format.format(date);
    }/*from w  ww . j  av a 2  s .  c om*/

    public static String formatISO8601Date(Date date, TimeZone timezone) {
        if (timezone == null) {
            throw new NullPointerException("timezone should not be null");
        }
        DateFormat format = new SimpleDateFormat(ISO8601DATE_WITH_MILLS_TIMEZONE_FORMAT);
        format.setTimeZone(timezone);
        return format.format(date);
    }
}

Related

  1. formatISO8601(final Date date)
  2. formatISO8601Date(Date d)
  3. formatISO8601Date(Date date)
  4. formatISO8601Date(Date date)
  5. formatIso8601Date(Date date)
  6. formatISO8601Date(final Calendar date)
  7. formatISO8601Date(final java.util.Date date)
  8. formatISO8601DateWOTime(final java.util.Date date)
  9. formatIso8601ForCCTray(Date date)