Java Date Create toDateStr(Date d)

Here you can find the source of toDateStr(Date d)

Description

to Date Str

License

Open Source License

Declaration

public static String toDateStr(Date d) 

Method Source Code

//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;
    }
}

Related

  1. toDateFormat(Date date)
  2. toDateFromLong(Long time)
  3. toDateHeader(long value)
  4. toDateList(Collection list)
  5. toDateQueryFormat(Date value)
  6. ToDateStr(Date dt)
  7. toDateStr(Object o)
  8. toDateText(Date date)
  9. toDateTime(Date date)