fork download
  1. import java.time.LocalDate;
  2. import java.time.OffsetDateTime;
  3. import java.time.ZoneId;
  4. import java.time.ZonedDateTime;
  5. import java.time.format.DateTimeFormatter;
  6.  
  7. class Main {
  8. public static void main(String[] args) {
  9. LocalDate date = LocalDate.parse("20150101", DateTimeFormatter.BASIC_ISO_DATE);
  10.  
  11. // Convert date into a ZonedDateTime at the start of the day in the
  12. // desired timezone e.g. ZoneId.of("Etc/UTC")
  13. ZonedDateTime zdt = date.atStartOfDay(ZoneId.of("Etc/UTC"));
  14.  
  15. // Convert the obtained ZonedDateTime into an OffsetDateTime
  16. OffsetDateTime odt = zdt.toOffsetDateTime();
  17. System.out.println(odt);
  18. }
  19. }
Success #stdin #stdout 0.15s 36972KB
stdin
Standard input is empty
stdout
2015-01-01T00:00Z