Is there a nicer/easier way of constructing LocalDateTime
object representing today at 6 AM than this?
LocalDateTime todayAt6 = LocalDateTime.now().withHour(6).withMinute(0).withSecond(0).withNano(0);
Somehow I don't like dealing with minutes/seconds/nano when all I want to say is now().withHours()
.
toString()); LocalDateTime ldtmdh = dateTime. withHour(12);//sets the hour of the day to 12. The other date time fields are not modified. System.
now() now() method of a LocalDateTime class used to obtain the current date-time from the system clock in the default time-zone. This method will return LocalDateTime based on system clock with default time-zone to obtain the current date-time.
The LocalDateTime class represents the date-time,often viewed as year-month-day-hour-minute-second and has got no representation of time-zone or offset from UTC/Greenwich.
LocalDate
has various overloaded atTime
methods, such as this one, which takes two arguments (hour of day and minute):
LocalDateTime todayAt6 = LocalDate.now().atTime(6, 0);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With