快速获取当天0点0分0秒(00:00:00),23点59分59秒(23:59:59)

// 利用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>
——————— 

原文:https://blog.csdn.net/qq_19260029/article/details/51489928 
 

    原文作者:春风一慕
    原文地址: https://blog.csdn.net/w584212179/article/details/89923862
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞