Java Date to String dateToString(Date date, String format)

Here you can find the source of dateToString(Date date, String format)

Description

date To String

License

Open Source License

Declaration

public static String dateToString(Date date, String format) 

Method Source Code

//package com.java2s;

import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
    public static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
    public static final String DATE_PATTERN_SS = "yyyyMMddHHmmssSS";

    public static String dateToString(Date date, String format) {
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        try {/*from ww w . j  a  v  a2s .  c  o m*/
            return sdf.format(date);
        } catch (Exception e) {
            return null;
        }
    }

    public static String format(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat(YYYY_MM_DD_HH_MM_SS);
        return sdf.format(date);
    }

    public static String format(Date date, String pattern) {
        return date == null ? " " : new SimpleDateFormat(pattern).format(date);
    }

    public static String format() {
        SimpleDateFormat sdf = new SimpleDateFormat(DATE_PATTERN_SS);
        return sdf.format(new Date());
    }
}

Related

  1. dateToString(Date date)
  2. dateToString(Date date, String dateFormat)
  3. dateToString(Date date, String formartStr)
  4. dateToString(Date date, String format)
  5. dateToString(Date date, String format)
  6. dateToString(Date date, String format)
  7. dateToString(Date date, String format)
  8. dateToString(Date date, String format)
  9. dateToString(Date date, String formatStr)