Here you can find the source of dateToString(Date date)
public static String dateToString(Date date)
//package com.java2s; // (c) 2012 B Smith-Mannschott -- Distributed under the Eclipse Public License import java.util.Date; import java.util.GregorianCalendar; import java.util.TimeZone; import java.util.regex.Pattern; public class Main { private static final TimeZone GMT = TimeZone.getTimeZone("GMT"); /**//from ww w. j a v a 2 s .co m * Return a String suitable for use as an edn {@code #inst}, given * a {@link Date}. * @return an RFC3339 compatible string. */ public static String dateToString(Date date) { GregorianCalendar c = new GregorianCalendar(GMT); c.setTime(date); String s = calendarToString(c); assert s.endsWith("+00:00"); return s.substring(0, s.length() - 6) + "-00:00"; } /** * Return a String suitable for use as an edn {@code #inst}, given * a {@link GregorianCalendar}. * @return an RFC3339 compatible string. */ public static String calendarToString(GregorianCalendar cal) { String s = String.format("%1$tFT%1$tT.%1$tL%1$tz", cal); /* s is almost right, but is missing the colon in the offset */ assert Pattern.matches(".*[-+][0-9]{4}$", s); int n = s.length(); return s.substring(0, n - 2) + ":" + s.substring(n - 2); } }