datetimeutility.java

来自「一个常用的电子商城的站点源码」· Java 代码 · 共 66 行

JAVA
66
字号
package com.publish.shop.util.javabeans;import java.sql.Timestamp;import java.text.Format;import java.text.SimpleDateFormat;public class DateTimeUtility {        public static String getFormatedTime(Timestamp date) {                if (date == null) return null;                return getFormatedDateTime(date).substring(11);        }        public static String getFormatedDateTime(Timestamp date) {                if (date == null) return null;                SimpleDateFormat lFormatTimestamp = new SimpleDateFormat(Constants.TIMESTAMP_PATTERN);            return lFormatTimestamp.format(date);        }    public static Timestamp getDateTime(String date, String time, Timestamp defaultValue){            StringBuffer buf = new StringBuffer();                Timestamp current = defaultValue;                SimpleDateFormat lFormatDate = new SimpleDateFormat(Constants.DATE_PATTERN);                SimpleDateFormat lFormatTime = new SimpleDateFormat(Constants.TIME_PATTERN);                SimpleDateFormat lFormatTimestamp = new SimpleDateFormat(Constants.TIMESTAMP_PATTERN);            if (Utility.isEmpty(date) && Utility.isEmpty(time)){               return defaultValue;            }            if (defaultValue == null) current = getCurrentTimeStamp();        if (Utility.isEmpty(date)) {                buf.append(lFormatDate.format(current));            } else {                    buf.append(date);            }            buf.append(" ");            if (Utility.isEmpty(time)) {                    buf.append(lFormatTime.format(current));            } else {                        buf.append(time);            }                Timestamp rtn = null;                try {           rtn =new Timestamp(lFormatTimestamp.parse(buf.toString()).getTime());                } catch (Exception e) {                }                return rtn;    }  public static String getCurTimeStamp()   {     SimpleDateFormat lSimpleDateFormat = new SimpleDateFormat();     lSimpleDateFormat.applyPattern("yyyy-MM-dd HH:mm:ss");     java.sql.Timestamp lTime =  (java.sql.Timestamp.valueOf(lSimpleDateFormat.format(new java.util.Date())));     return getFormatedDateTime(lTime);   }  public static Timestamp getCurrentTimeStamp()   {     SimpleDateFormat lSimpleDateFormat = new SimpleDateFormat();     lSimpleDateFormat.applyPattern("yyyy-MM-dd HH:mm:ss");     return (java.sql.Timestamp.valueOf(lSimpleDateFormat.format(new java.util.Date())));   }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?