In this Q&A, we'll go over how to create date time objects with start of day and end of day times. We'll use the date/time classes in java.time package and not the pre Java 8 Date and Time classes.
See the code snippet below on how to construct date or datetime objects. Code is self-explanatory.
// Date without time.
LocalDate ld = LocalDate.now();
System.out.println( ld.toString());
// start of date and end of date times
LocalDateTime sod = ld.atTime(LocalTime.MIDNIGHT);
LocalDateTime eod = ld.atTime(LocalTime.MAX);
System.out.println( sod.toString());
System.out.println( eod.toString());
// start of date with zone
ZonedDateTime zdt = sod.atZone(ZoneId.systemDefault());
System.out.println( zdt.toString());
Comments
Post a Comment