⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 datetimeutility.java

📁 一个常用的电子商城的站点源码
💻 JAVA
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -