2

我正在获取当前时区,

String defaultTimeZone = ""+TimeZone.getDefault();

现在我想得到我正在使用的时间,

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");

例如,如果 currentTimeZone = "Calcutta" 那么它的时间是 +0530 就像,

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss +0530");

我正在使用 Java1.4 和 RIM API,在 Java 1.5 中你可以写成“yyyy-MM-dd HH:mm:ss Z”来获得“+0530”

那么如何在 Java 1.4 中做到这一点呢?


我检查使用,

boolean isDayLightSavings = _timeZone.useDaylightTime();
if(isDayLightSavings)
{               
        gmtOffset = _timeZone.getOffset(1, _calendar.get(Calendar.YEAR), _calendar.get(Calendar.MONTH), _calendar.get(Calendar.DATE), _calendar.get(Calendar.DAY_OF_WEEK), _calendar.get(Calendar.MILLISECOND));
}

但与使用 DST 的 TimeZones 的前进/后退 1 小时的结果相同。(即对于使用 DST 的 TimeZones,当我使用 getOffset(..) 时,Blackberry 设备不使用 DST)

所以我应该在 BB 设备中启用 DST。如果是,那么该怎么做?

4

2 回答 2

0

这个怎么样

Calendar cal = Calendar.getInstance();
return cal.getTimeZone();

公历对于所有日期/时间都非常方便。

于 2009-10-28T16:50:40.413 回答
0

更具体一点,试试这个:

日历 cal = Calendar.getInstance();
时区 timeZone = cal.getTimeZone();
int rawOffset = timeZone.getRawOffset();

原始偏移量以毫秒为单位。除以 3,600,000 得到小时偏移量。

于 2009-10-28T17:02:01.623 回答