Set time to 00:00:00

前端 未结 12 2161
时光说笑
时光说笑 2020-11-29 20:04

I have a problem resetting hours in Java. For a given date I want to set the hours to 00:00:00.

This is my code :

/**
     * Resets milliseconds, se         


        
12条回答
  •  天命终不由人
    2020-11-29 20:53

    java.time

    Using the java.time framework built into Java 8 and later. See Tutorial.

    import java.time.LocalTime;
    import java.time.LocalDateTime;
    
    LocalDateTime now = LocalDateTime.now(); # 2015-11-19T19:42:19.224
    # start of a day
    now.with(LocalTime.MIN); # 2015-11-19T00:00
    now.with(LocalTime.MIDNIGHT); # 2015-11-19T00:00
    

    If you do not need time-of-day (hour, minute, second etc. parts) consider using LocalDate class.

    LocalDate.now(); # 2015-11-19
    

提交回复
热议问题