需求描述:主要用于报表统计时的时间处理
代码:
private void dealTime(String theDay) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Calendar cale = Calendar.getInstance();
// 获取当月第一天和最后一天
String firstday, lastday;
Date date = null;
try {
date = format.parse(theDay);
} catch (ParseException e) {
e.printStackTrace();
}
cale.setTime(date);
// 获取前月的第一天
cale.add(Calendar.MONTH, 0);
cale.set(Calendar.DAY_OF_MONTH, 1);
firstday = format.format(cale.getTime());
cale.add(Calendar.MONTH, 1);
cale.set(Calendar.DAY_OF_MONTH, 0);
lastday = format.format(cale.getTime());
System.out.println("本月第一天和最后一天分别是 : " + firstday +" 00:00:00" + " and " + lastday + " 23:59:59");
}
1329

被折叠的 条评论
为什么被折叠?



