java.time equivalent of Joda-Time `withTimeAtStartOfDay`? (get first moment of the day)

后端 未结 4 1719
野性不改
野性不改 2021-02-19 07:02

In the Joda-Time library, the DateTime class offers a method withTimeAtStartOfDay to get the first moment of the day. You might think of that moment as \"midnight\". That first

4条回答
  •  北荒
    北荒 (楼主)
    2021-02-19 07:25

    You can use LocalDate to do this:

    // or a similar factory method to get the date you want
    LocalDateTime startOfDay = LocalDate.now().atStartOfDay();
    

    Combines this date with the time of midnight to create a LocalDateTime at the start of this date. This returns a LocalDateTime formed from this date at the time of midnight, 00:00, at the start of this date.

    https://docs.oracle.com/javase/8/docs/api/java/time/LocalDate.html#atStartOfDay--

提交回复
热议问题