Here you can find the source of getDateTimeStr(Date date)
Parameter | Description |
---|---|
date | date |
static public String getDateTimeStr(Date date)
//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); } }