Java SQL Time From getDateTimeStr(Date date)

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

Description

getDateStr get a string with format YYYY-MM-DD HH:mm:ss from a Date object

License

Open Source License

Parameter

Parameter Description
date date

Return

String

Declaration

static public String getDateTimeStr(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 {
    /**/*from   w  ww.j  a v  a2  s.  c  o  m*/
     * format pattern : yyyy-MM-dd
     */
    public static final SimpleDateFormat FORMAT_YYYY_MM_DD = new SimpleDateFormat("yyyy-MM-dd");
    /**
     * format pattern : yyyy-MM-dd HH:mm:ss
     */
    public static final SimpleDateFormat FORMAT_YYYY_MM_DD_HMS = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    /**
     * getDateStr get a string with format YYYY-MM-DD HH:mm:ss from a Date
     * object
     * 
     * @param date
     *            date
     * @return String
     */
    static public String getDateTimeStr(Date date) {

        if (date != null) {
            return FORMAT_YYYY_MM_DD_HMS.format(date);
        } else
            return "";
    }

    static public String getDateTimeStr(java.sql.Date date, double time) {
        String dateStr = FORMAT_YYYY_MM_DD.format(date);
        Double d = new Double(time);
        String timeStr = String.valueOf(d.intValue()) + ":00:00";

        return dateStr + " " + timeStr;
    }

    static public String format(Date date, String formatText) throws Exception {
        SimpleDateFormat format = new SimpleDateFormat(formatText);
        return format.format(date);
    }
}

Related

  1. getDateTime(String s)
  2. getDatetime(String value)
  3. getDateTimeBySecond(long timeMillis)
  4. getDateTimeFormat()
  5. getDateTimeRtnTime(Date date, String time)
  6. getDateTimeString(java.sql.Date dd)
  7. getDateTimeString(String format)
  8. getDateTimeStringFromCalendar(Calendar calendar)
  9. getDateTimeTypeString(Connection conn)