Java-在没有TimeZone的情况下创建日历 [英] Java - Creating a Calendar without a TimeZone
问题描述
我首先要说的是,我已经阅读了多个与此类似的主题,但没有一个真正解决了我的问题。
我也想指出,我尝试不使用任何 SimpleDateFormat
和 joda.DateTime
成功。
I would like to start by saying that I've read several threads similar to this one, but none of them really solved my problem.
I would also like to state that I've tried to use SimpleDateFormat
and joda.DateTime
without any success.
问题如下:
我有一个Calendar对象,该对象保存有关特定对象的信息。日期:2008-04-30T00:00:00Z
使用 calendar.getTime()
方法时,我会得到不同的结果,因为我知道该方法正在寻找对于本地值
I have a Calendar object that holds the information about a specific date: 2008-04-30T00:00:00Z
When using the calendar.getTime()
method I can get different results because I know that that method is looking for the local value
因此:
UK: 2008-04-30T01:00:00.000+0100
US: 2008-04-30T20:00:00.000-0400
但是我想得到一个Date对象,它只保留日期和时间值 2008-04-30T00:00:00,而完全忽略了任何时区。
But I would like to get a Date object that holds just the Date and Time values "2008-04-30T00:00:00" ignoring completely any timezone.
我该怎么做?
正如我之前提到的,我尝试使用
SimpleDateFormat sf = new SimpleDateFormat ( yyyy-MM-dd'T'HH:mm:ss)
,但我总是得到相同的结果。
As I mentioned before I tried to use
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss")
but I always end up with the same results.
任何帮助
Any help would be really appreciated Cheers.
推荐答案
发现您可以使用以下代码清除时区:
Found out that you can clear the Timezone by using code below:
Calendar cal = Calendar.getInstance();
cal.clear(Calendar.ZONE_OFFSET);
这篇关于Java-在没有TimeZone的情况下创建日历的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!