How to obtain the start time and end time of a day?

前端 未结 14 882
心在旅途
心在旅途 2020-11-27 10:23

How to obtain the start time and end time of a day?

code like this is not accurate:

 private Date getStartOfDay(Date date) {
    Calendar calendar =          


        
14条回答
  •  遥遥无期
    2020-11-27 10:34

    I tried this code and it works well!

    final ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
    final ZonedDateTime startofDay =
        now.toLocalDate().atStartOfDay(ZoneOffset.UTC);
    final ZonedDateTime endOfDay =
        now.toLocalDate().atTime(LocalTime.MAX).atZone(ZoneOffset.UTC);
    

提交回复
热议问题