Android Date to ISO Format javaDateToIso8601(Date date)

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

Description

java Date To Iso

Declaration

public static String javaDateToIso8601(Date date) 

Method Source Code

//package com.java2s;

import java.text.DateFormat;

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

public class Main {
    private static final ThreadLocal<DateFormat> ISO8601Format = new ThreadLocal<DateFormat>() {
        @Override/*w  ww. j a v a  2 s  . c  o m*/
        protected DateFormat initialValue() {
            return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.US);
        }
    };

    public static String javaDateToIso8601(Date date) {
        if (date == null)
            return "";
        DateFormat formatter = ISO8601Format.get();
        return formatter.format(date);
    }
}