Java Date to String date2Str(Date date)

Here you can find the source of date2Str(Date date)

Description

date Str

License

Apache License

Declaration

public static String date2Str(Date date) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.text.SimpleDateFormat;
import java.util.*;

public class Main {
    public static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    public static SimpleDateFormat customerFormat = new SimpleDateFormat("yyyyMMdd");

    public static String date2Str(Date date) {
        try {/*from   www .j a v  a 2s  .  c  o  m*/
            return dateFormat.format(date);
        } catch (Exception ex) {
            return "";
        }
    }

    public static String date2Str(Date date, String pattern) {
        try {
            customerFormat.applyPattern(pattern);
            return customerFormat.format(date);
        } catch (Exception ex) {
            return "";
        }
    }
}

Related

  1. convertToString(String format, Date date)
  2. date2str(Calendar c)
  3. date2Str(Calendar c, String format)
  4. date2Str(Date aDate)
  5. Date2Str(Date date)
  6. date2Str(Date date)
  7. date2Str(Date date, String dateFormat)
  8. date2Str(Date date, String format)
  9. date2Str(Date date, String format)