fork download
  1. import java.time.Instant;
  2. import java.time.ZoneId;
  3. import java.time.ZonedDateTime;
  4. import java.time.format.DateTimeFormatter;
  5.  
  6. public class Main {
  7. public static void main(String[] args) {
  8. String strDate = "2021-11-25";
  9. String strTime = "15:20";
  10. DateTimeFormatter dtf = DateTimeFormatter.ISO_LOCAL_DATE_TIME.withZone(ZoneId.systemDefault());
  11. ZonedDateTime zdt = ZonedDateTime.parse(strDate + "T" + strTime, dtf);
  12. Instant instant = zdt.toInstant();
  13. System.out.println(instant);
  14. }
  15. }
Success #stdin #stdout 0.13s 53868KB
stdin
Standard input is empty
stdout
2021-11-25T15:20:00Z