1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package app;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
public class Main
{
public static void main(String[] args)
{
String dateTimeFormat = "yyyy-MM-dd HH:mm:ss";
ZoneId fromTz = ZoneId.of("Europe/London");
ZoneId toTz = ZoneId.of("America/New_York");
String fromDateTime = "2020-09-12 20:30:00";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(dateTimeFormat);
ZonedDateTime dt = LocalDateTime.parse(fromDateTime, formatter).atZone(fromTz);
dt = dt.withZoneSameInstant(toTz);
String toDateTime = formatter.format(dt);
System.out.println(toDateTime);
}
}
Leave a Comment
Cancel reply