This method converts this local date to a new LocalDateTime instance with time portion having start of this date i.e. 00:00
This method converts this local date to a new ZonedDateTime instance with time portion having start of this date at the earliest valid time according to the rules in the provided time-zone.
package com.logicbig.example.localdate;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.Month;
public class AsStartOfDayExample {
public static void main (String[] args) {
LocalDate d = LocalDate.of(2012, Month.FEBRUARY, 22);
LocalDateTime dateTime = d.atStartOfDay();
System.out.println(dateTime);
//above is equivalent to
LocalDateTime dateTime1 = LocalDateTime.of(d, LocalTime.MIDNIGHT);
System.out.println(dateTime1);
}
}
Output
2012-02-22T00:00
2012-02-22T00:00
package com.logicbig.example.localdate;
import java.time.LocalDate;
import java.time.Month;
import java.time.ZoneId;
import java.time.ZonedDateTime;
public class AsStartOfDayExample2 {
public static void main (String[] args) {
LocalDate d = LocalDate.of(2012, Month.FEBRUARY, 22);
ZonedDateTime zdt = d.atStartOfDay(ZoneId.of("Asia/Tokyo"));
System.out.println(zdt);
System.out.println(zdt.toLocalTime());
System.out.println(zdt.toOffsetDateTime());
System.out.println("---");
ZonedDateTime zdt2 = d.atStartOfDay(ZoneId.systemDefault());
System.out.println(zdt2);
System.out.println(zdt2.toLocalTime());
System.out.println(zdt2.toOffsetDateTime());
}
}
Output
2012-02-22T00:00+09:00[Asia/Tokyo]
00:00
2012-02-22T00:00+09:00
---
2012-02-22T00:00-06:00[America/Chicago]
00:00
2012-02-22T00:00-06:00