Java Date to String date2String(java.util.Date date, String format)

Here you can find the source of date2String(java.util.Date date, String format)

Description

date String

License

Open Source License

Declaration

public static String date2String(java.util.Date date, String format) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.text.SimpleDateFormat;

public class Main {
    private static String defaultFormat = "yyyy-MM-dd";

    public static String date2String(java.util.Date date, String format) {
        if (date == null) {
            return null;
        }//from  w  w  w.ja  va2s  .  co  m
        if (format == null || "".equals(format)) {
            format = defaultFormat;
        }
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
        String dateOfStr = "";
        try {
            dateOfStr = simpleDateFormat.format(date);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dateOfStr;
    }
}

Related

  1. date2String(Date date, String format)
  2. Date2String(Date date, String formatPattern)
  3. date2String(Date date, String pattern)
  4. date2String(Date source, String formatString)
  5. date2String(Date value)
  6. date2String(java.util.Date date, String pattern)
  7. date2String(String formater, Date aDate)
  8. date2String(String pattern, Date date)
  9. date2String2(Date date)