【发布时间】:2019-02-05 17:57:14
【问题描述】:
我有一个输入“+04:00”
我可以使用什么 API 从中获取时区?
到目前为止, 1) 我调查了 joda - https://www.joda.org/joda-time/apidocs/org/joda/time/DateTimeZone.html
static DateTimeZone forOffsetHoursMinutes(int hoursOffset, int minutesOffset)
不确定这是否理想。
2) 我检查了 Timezone 类。
http://docs.oracle.com/javase/6/docs/api/java/util/TimeZone.html#getTimeZone%28java.lang.String%29
getTimeZone
public static TimeZone getTimeZone(String ID)
Gets the TimeZone for the given ID.
Parameters:
ID - the ID for a TimeZone, either an abbreviation such as "PST", a full name such as "America/Los_Angeles", or a custom ID such as "GMT-8:00". Note that the support of abbreviations is for JDK 1.1.x compatibility only and full names should be used.
Returns:
the specified TimeZone, or the GMT zone if the given ID cannot be understood.
有人能解释一下如何将自定义 ID 作为此函数的输入吗?
【问题讨论】:
-
请阅读the timezone tag wiki中的“时区!=偏移”