Java SQL Date to String toString(Date date)

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

Description

to String

License

Open Source License

Declaration

public static String toString(Date date) 

Method Source Code


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

import java.sql.Timestamp;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {

    public static String toString(Date date) {
        if (date == null) {
            return "";
        }//  w w w.  jav  a  2 s  .  c  o  m
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.format(date);
    }

    public static Object toString(Timestamp timestamp) {
        if (timestamp == null) {
            return "";
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.format(timestamp);
    }
}

Related

  1. date2str(java.util.Date date)
  2. date2String(final java.sql.Date value)
  3. toString(Date date)
  4. toString(Date date, String dateFormat)
  5. toString(Date date, String format)
  6. toString(Date obj)