Java Date Format ISO toISOString(Date date, String format, TimeZone tz)

Here you can find the source of toISOString(Date date, String format, TimeZone tz)

Description

Render date

License

Open Source License

Parameter

Parameter Description
date the date obj
format - if not specified, will use FORMAT_DATE_ISO
tz - tz to set to, if not specified uses local timezone

Return

the ISO-formatted date string

Declaration

public static String toISOString(Date date, String format, TimeZone tz) 

Method Source Code


//package com.java2s;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

public class Main {
    /** The date format in ISO. */
    public static String FORMAT_DATE_ISO = "yyyy-MM-dd'T'HH:mm:ss'Z'";

    /**//from w w  w. j a va  2  s  .c  o m
     * Render date
     * 
     * @param date
     *          the date obj
     * @param format
     *          - if not specified, will use FORMAT_DATE_ISO
     * @param tz
     *          - tz to set to, if not specified uses local timezone
     * @return the ISO-formatted date string
     */
    public static String toISOString(Date date, String format, TimeZone tz) {
        if (format == null) {
            format = FORMAT_DATE_ISO;
        }
        if (tz == null) {
            tz = TimeZone.getDefault();
        }
        DateFormat f = new SimpleDateFormat(format);
        f.setTimeZone(tz);
        return f.format(date);
    }

    public static String toISOString(Date date) {
        return toISOString(date, FORMAT_DATE_ISO, TimeZone.getDefault());
    }
}

Related

  1. toIso8601(Date dateTime)
  2. toISO8601(Date pDate)
  3. toISO8601FileSystemCompatible(Calendar calendar)
  4. toISODate(String format, String value)
  5. toISODateRealTimeFormat(Date iDate)
  6. toIsoTime(Date timestamp)
  7. toIsoTime(Date timestamp)
  8. toStringISO8601(Calendar cal)