?? datetimeutility.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()))); }}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -