Java Date Format ISO iso8601(final Date date)

Here you can find the source of iso8601(final Date date)

Description

iso

License

Open Source License

Declaration

public static String iso8601(final Date date) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
    /**// w ww .j a  va  2 s.c  o  m
     * Encodes date value into ISO8601 that can be compared 
     * lexicographically.
     * 
     * @return string representation of the date value for the current date.
     */
    public static String iso8601() {
        return iso8601(new Date());
    }

    public static String iso8601(final Date date) {
        final SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
        // Java doesn't handle ISO8601 nicely: need to add ':' manually 
        final String result = dateFormatter.format(date);
        return result.substring(0, result.length() - 2) + ":" + result.substring(result.length() - 2);
    }
}

Related

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