Here you can find the source of toDateStr(Date d)
public static String toDateStr(Date d)
//package com.java2s; //License from project: Open Source License import java.text.SimpleDateFormat; import java.util.Date; public class Main { private static final String IOS_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss.SSS"; private static final String IOS_DATE_FORMAT_OLD = "yyyy-MM-dd HH:mm:ss"; public static String toDateStr(Date d) { if (d == null) { return null; }/*w w w. j a v a 2 s.c o m*/ String ret = null; try { ret = new SimpleDateFormat(IOS_DATE_FORMAT).format(d); } catch (Exception e) { ret = new SimpleDateFormat(IOS_DATE_FORMAT_OLD).format(d); } return ret; } }