fork download
  1. import java.time.ZoneId;
  2. import java.time.ZonedDateTime;
  3.  
  4. public class Main {
  5. public static void main(String[] args) {
  6. ZoneId sourceZone = ZoneId.of("Europe/Berlin");
  7. ZonedDateTime zdtSource = ZonedDateTime.now(sourceZone);
  8. System.out.println(zdtSource);
  9.  
  10. ZoneId targetZone = ZoneId.of("America/New_York");
  11. ZonedDateTime zdtTarget = zdtSource.withZoneSameInstant(targetZone);
  12. System.out.println(zdtTarget);
  13. }
  14. }
Success #stdin #stdout 0.13s 51844KB
stdin
Standard input is empty
stdout
2021-08-10T20:07:38.823252+02:00[Europe/Berlin]
2021-08-10T14:07:38.823252-04:00[America/New_York]