How to get the start and end times of a day

后端 未结 10 733
无人及你
无人及你 2020-12-24 00:29

In my C# app, I pass a string variable that is of format yyyymmdd-yyyymmdd that represents a from and to date. I want to get the start and end times for these dates respecti

10条回答
  •  感情败类
    2020-12-24 00:51

    In Java 8, you can do it using LocalDate as follows:

        LocalDate localDateStart = LocalDate.now();
        Date startDate = Date.from(localDateStart.atStartOfDay(ZoneId.systemDefault()).toInstant());
    
        LocalDate localDateEnd = localDateStart.plusDays(1);
        Date endDate = Date.from(localDateEnd.atStartOfDay(ZoneId.systemDefault()).toInstant());
    

提交回复
热议问题