Here you can find the source of convertDateToString(Date date, boolean millis)
public static String convertDateToString(Date date, boolean millis)
//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 { private static final Date ONE_CE = new Date(-62135769600000L); public static String convertDateToString(Date date, boolean millis) { if (date == null) { return null; } else {/*from w ww.j a va 2 s . co m*/ DateFormat df; if (millis) { df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); } else { df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); } df.setTimeZone(TimeZone.getTimeZone("GMT")); if (date.before(ONE_CE)) { StringBuilder sb = new StringBuilder(df.format(date)); sb.insert(0, "-"); return sb.toString(); } else { return df.format(date); } } } }