Java SQL Date From getDateTime()

Here you can find the source of getDateTime()

Description

get Date Time

License

Open Source License

Declaration

public static String getDateTime() 

Method Source Code

//package com.java2s;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {

    public static String getDateTime() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.format(new Date());
    }//from   w  w  w  .j av  a 2s . co  m

    public static java.sql.Timestamp getDateTime(String sDt) {
        try {
            return java.sql.Timestamp.valueOf(sDt); // sDt
            // format:yyyy-mm-dd
            // hh:mm:ss.fffffffff
        } catch (IllegalArgumentException iae) {
            sDt = sDt + " 00:00:00";
            try {
                return java.sql.Timestamp.valueOf(sDt);
            } catch (Exception e) {
                return null;
            }
        }
    }
}

Related

  1. getCurrTime()
  2. getCurTime()
  3. getDatabaseLocalTime(Time databaseDate)
  4. getDateTime()
  5. getDateTime()
  6. getDateTime(final int year, final int month, final int day, final int hour, final int minute, final int second)
  7. getDateTime(Object value)
  8. toDate(Calendar cal)
  9. toDate(int value)