Java Date to String dateToStr(Date date)

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

Description

date To Str

License

Open Source License

Declaration

public static String dateToStr(Date date) 

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 NORMAL_PATTERN = "yyyy-MM-dd HH:mm:ss";

    public static String dateToStr(Date date) {
        if (date == null) {
            return "";
        }//from  ww  w .  java 2 s  .  c o m
        return dateToString(date, NORMAL_PATTERN);
    }

    public static String dateToStr() {
        return dateToStr(new Date());
    }

    public static String dateToString(Date date, String pattern) {
        if (date == null) {
            date = new Date();
        }
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        return sdf.format(date);
    }

    @Deprecated
    public static String dateToString(Date date) {
        return dateToStr(date);
    }
}

Related

  1. dateToRelativeTime(Date date)
  2. dateToRFC1123(Date date)
  3. dateToRFC3339(Date d)
  4. dateToStr(Date date)
  5. dateToStr(Date date)
  6. dateToStr(Date date)
  7. dateToStr(Date date, int type)
  8. dateToStr(Date date, String format)
  9. dateToStr(Date date, String format)