Here you can find the source of formatISO8601Date(Date date)
public static String formatISO8601Date(Date date)
//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); } }