日期的处理:
Calendar cal = Calendar.getInstance(); Date dS = sdf.parse(monitorForm.getO_date_start()); Date dE = sdf.parse(monitorForm.getO_date_end()); if (dS.getTime() > dE.getTime()) { throw new Exception("起始时间不能大于结束时间!"); } cal.setTime(dE); cal.add(Calendar.DATE, -31); dE = cal.getTime(); if (dS.getTime() <= dE.getTime()) { throw new Exception("时间相隔不能超过31天(只允许统计一个月)!"); }
日期格式化:
private final static DateFormat SDF= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//24小时制 private final static DateFormat SDF= new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");//12小时制
log4j日志:
private final static Logger LOG= Logger.getLogger(BatchRechargeManager.class);
保留两位小数四舍五入:
private static DecimalFormat FORMAT= null; static { format = new DecimalFormat("#0.00"); format.setRoundingMode(RoundingMode.HALF_UP);// 四舍五入 }
单例模式:
private static BatchRechargeManager INSTANCE= null; private BatchRechargeManager() { } private static synchronized void synInit() { if (INSTANCE== null) { INSTANCE= new BatchRechargeManager(); } } public static BatchRechargeManager getInstance() { if (INSTANCE == null) { synInit(); } return INSTANCE; }
本文出自 “zhanglunc” 博客,请务必保留此出处http://zhanglunc.blog.51cto.com/11144997/1750237
原文:http://zhanglunc.blog.51cto.com/11144997/1750237