java.time
这些旧的日期时间类已被Java 8及更高版本中内置的java.time框架所取代。
如果您只想要UTC中的当前时间,请使用Instant该类。Instantnow=Instant.now();
EST不是时区,正如Jon Skeet在正确答案中所解释的那样。这样的3-4个字母代码既不是标准化也不是唯一的,并且进一步混淆了夏令时(DST)。使用“continent / region”格式的正确时区名称。
也许你的意思是北美东海岸的东部标准时间?还是埃及标准时间?还是欧洲标准时间?ZoneIdzoneId=ZoneId.of("America/New_York");ZoneIdzoneId=ZoneId.of("Africa/Cairo");ZoneIdzoneId=ZoneId.of("Europe/Lisbon");
使用任何此类ZoneId对象将当前时刻调整到特定时区以生成ZonedDateTime对象。ZonedDateTimezdt=ZonedDateTime.now(zoneId);
通过从第一个生成另一个ZonedDateTime对象,将ZonedDateTime调整到不同的时区。java.time框架使用不可变对象而不是更改(变异)现有对象。ZonedDateTimezdtGuam=zdt.withZoneSameInstant(ZoneId.of("Pacific/Guam"));