Java SQL Date to String date2str(java.util.Date date)

Here you can find the source of date2str(java.util.Date date)

Description

datestr

License

Apache License

Declaration

public static String date2str(java.util.Date date) 

Method Source Code


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

import java.text.SimpleDateFormat;

public class Main {
    static public SimpleDateFormat MMddYYYY_HHmmss = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    static public SimpleDateFormat yyyyMMdd = new SimpleDateFormat("yyyy-MM-dd");

    public static String date2str(java.util.Date date) {
        if (date == null)
            return "";
        try {//from  w  ww.j  a  v a2  s .co  m
            return MMddYYYY_HHmmss.format(date);
        } catch (Exception e) {
            return "";
        }
    }

    static public String date2str(java.sql.Date date) {
        if (date == null)
            return "";
        try {
            return yyyyMMdd.format(date);
        } catch (Exception e) {
            return "";
        }

    }
}

Related

  1. date2String(final java.sql.Date value)
  2. toString(Date date)
  3. toString(Date date)
  4. toString(Date date, String dateFormat)