Here you can find the source of format(Date date)
public static String format(Date date)
//package com.java2s; /**/*from ww w . j a v a2 s . c om*/ * The contents of this file are subject to the license and copyright * detailed in the LICENSE and NOTICE files at the root of the source * tree and available online at * * http://www.dspace.org/license/ */ import java.text.SimpleDateFormat; import java.util.Date; import java.util.TimeZone; public class Main { public static String format(Date date) { return format(date, true); } public static String format(Date date, boolean init) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.'000Z'"); if (!init) sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.'999Z'"); // We indicate that the returned date is in Zulu time (UTC) so we have // to set the time zone of sdf correct. sdf.setTimeZone(TimeZone.getTimeZone("ZULU")); String ret = sdf.format(date); return ret; } }