我有一个这种格式的日期字符串,2019-01-01T18:46:19
我想将它转换为这种格式06:46 pm AEST 01/01/19
,例如带有缩写的澳大利亚时区。我怎样才能在 Java 中做到这一点?
您可以将较新的java.time
API 用于此任务:
import java.time.LocalDateTime;
import java.time.ZonedDateTime;
import java.time.ZOneId;
import java.time.format.DateTimeFormatter;
ZoneId zone = ZoneId.of("Australia/Sydney");
LocalDateTime ldt = LocalDateTime.parse("2019-01-01T18:46:19") ;
ZonedDateTime zdt = ZonedDateTime.of(ldt, zone);
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("hh:mm a z dd/MM/yy");
System.out.println(dtf.format(zdt));
输出:
澳大利亚东部夏令时间 06:46 PM 01/01/19
注意:您在问题中的格式对于您是想要日/月/年还是美国的月/日/年不明确,但我假设澳大利亚在更喜欢日/月/年方面跟随英国。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句