【发布时间】:2017-03-22 06:15:30
【问题描述】:
我想从给定的时区获取当前时间,例如“IST”或“印度标准时间”等。 当输入为“印度标准时间”或“协调世界时间”时,我无法获得时间。它仅适用于“IST”或“UTC”或“EST”等。 我试过 Joda-Time 和 SimpleDateFormat。
SimpleDateFormat sd = new SimpleDateFormat(
"yyyy.MM.dd G 'at' HH:mm:ss z");
Date date = new Date();
sd.setTimeZone(TimeZone.getTimeZone("IST"));
System.out.println(sd.format(date));
DateTime now = new DateTime();
//DateTimeZone LDateTimeZone = DateTimeZone.forID( "Asia/Kolkata" );
DateTimeZone LDateTimeZone = DateTimeZone.forID( "IST" ); //deprecated
System.out.println( "Joda-Time zone: " + now.toDateTime( LDateTimeZone ) );
有没有办法同时处理这两个输入?
【问题讨论】:
-
始终使用完整的 IANA tz 数据库名称 -
Asia/Kolkata。缩写不是唯一的(印度/以色列/爱尔兰?),人性化的名称是特定于语言/地区的。
标签: java datetime timezone jodatime simpledateformat