Java Date to String dateToString(Date date)

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

Description

date To String

License

Apache License

Declaration

public static String dateToString(Date date) 

Method Source Code

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

import java.text.SimpleDateFormat;

public class Main {

    public static String dateToString(Date date) {
        if (date == null)
            return "";
        return FormatDate(date, "yyyy-MM-dd HH:mm:ss");
    }// w  w w .  ja  v a 2  s.  co  m

    public static String dateToString(Date date, String sf) {
        if (date == null)
            return "";
        return FormatDate(date, sf);
    }

    public static String FormatDate(Date date, String sf) {
        if (date == null)
            return "";
        SimpleDateFormat dateformat = new SimpleDateFormat(sf);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        if (date.getHours() == 0)
            return sdf.format(date);
        else
            return dateformat.format(date);
    }
}

Related

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