赞
踩
- // 利用Apache lang包快速获取凌晨0点0分0秒,23点59分59秒字符串
- System.out.println(DateFormatUtils.format(new Date(), "yyyy-MM-dd 00:00:00"));
- System.out.println(DateFormatUtils.format(new Date(), "yyyy-MM-dd 23:59:59"));
- // 获取当天凌晨0点0分0秒Date
- Calendar calendar1 = Calendar.getInstance();
- calendar1.set(calendar1.get(Calendar.YEAR), calendar1.get(Calendar.MONTH), calendar1.get(Calendar.DAY_OF_MONTH),
- 0, 0, 0);
- Date beginOfDate = calendar1.getTime();
- System.out.println(beginOfDate);
- // 获取当天23点59分59秒Date
- Calendar calendar2 = Calendar.getInstance();
- calendar2.set(calendar2.get(Calendar.YEAR), calendar2.get(Calendar.MONTH), calendar2.get(Calendar.DAY_OF_MONTH),
- 23, 59, 59);
- Date endOfDate = calendar2.getTime();
- System.out.println(endOfDate);
依次输出结果:
2016-05-24 00:00:00
2016-05-24 23:59:59
Tue May 24 00:00:00 CST 2016
Tue May 24 23:59:59 CST 2016
附:Apache lang Maven地址
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.3.2</version>
</dependency>
推荐文章:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。