fork download
  1. import java.time.Instant;
  2. import java.time.LocalDate;
  3. import java.time.LocalTime;
  4. import java.time.ZoneId;
  5. import java.time.ZonedDateTime;
  6.  
  7. public class Main {
  8. public static void main(String[] args) {
  9. String strDate = "2021-11-25";
  10. String strTime = "15:20";
  11. ZonedDateTime zdt = ZonedDateTime.of(LocalDate.parse(strDate), LocalTime.parse(strTime),
  12. ZoneId.systemDefault());
  13. // Alternatively
  14. // ZonedDateTime zdt = ZonedDateTime.of(LocalDateTime.of(LocalDate.parse(strDate), LocalTime.parse(strTime)),
  15. // ZoneId.systemDefault());
  16.  
  17. Instant instant = zdt.toInstant();
  18. System.out.println(instant);
  19. }
  20. }
Success #stdin #stdout 0.1s 49552KB
stdin
Standard input is empty
stdout
2021-11-25T15:20:00Z