Android 从当前时区转换为UTC减量2小时,而不是1小时

Android 从当前时区转换为UTC减量2小时,而不是1小时,android,datetime,datetimeoffset,android-date,java-time,Android,Datetime,Datetimeoffset,Android Date,Java Time,我想将当前时区的日期转换为UTC 结果对我来说是不可理解的 代码: 和LogCat结果为: 03-29 20:31:46.804: I/myDateFunctions(18413): the input param is:2014-04-29 20:00:00 03-29 20:31:47.005: I/myDateFunctions(18413): the input param after it is converted to Date:Tue Apr 29 20:00:00 CEST 20

我想将当前时区的日期转换为UTC

结果对我来说是不可理解的

代码:

和LogCat结果为:

03-29 20:31:46.804: I/myDateFunctions(18413): the input param is:2014-04-29 20:00:00
03-29 20:31:47.005: I/myDateFunctions(18413): the input param after it is converted to Date:Tue Apr 29 20:00:00 CEST 2014
03-29 20:31:47.005: I/myDateFunctions:(18413): my current Timezone:Central European Time +1
03-29 20:31:47.005: I/myDateFunctions(18413): the output, after i converted to UTC timezone:2014-04-29 18:00:00
如你所见: 我的时区是CET(GMT+1)


那么,如果我的输入是20:00,为什么我会返回18:00而不是19:00呢?

问题是夏令时。UTC没有,如果您的UTC有,则在一年中的部分时间内,差异将增加1小时。

这似乎是正确的

我只想说明使用Joda Time或java.Time比使用众所周知的麻烦的java.util.Date和.Calendar类更容易完成这项工作

乔达时间 在2.4中


你的时区有夏令时吗?如果是这样的话,这可能会增加1小时的转换时间(UTC没有)。我总是想知道为什么StackOverflow中的ppl害怕给出答案。也许是因为落选?嗯,你说得对。请把这个写下来作为答案,这样我就可以接受了。我在猜测的时候会用一个注释,所以人们看这个列表时不会认为它已经被回答了。
03-29 20:31:46.804: I/myDateFunctions(18413): the input param is:2014-04-29 20:00:00
03-29 20:31:47.005: I/myDateFunctions(18413): the input param after it is converted to Date:Tue Apr 29 20:00:00 CEST 2014
03-29 20:31:47.005: I/myDateFunctions:(18413): my current Timezone:Central European Time +1
03-29 20:31:47.005: I/myDateFunctions(18413): the output, after i converted to UTC timezone:2014-04-29 18:00:00
String inputRaw = "2014-04-29 20:00:00";
String input = inputRaw.replace( " ", "T" );
DateTimeZone timeZoneIntendedByString = DateTimeZone.forID( "America/Montreal" ); // Or DateTimeZone.getDefault();
DateTime dateTime = new DateTime( input, timeZoneIntendedByString );
DateTime dateTimeUtc = dateTime.withZone( DateTimeZone.UTC ); // Adjust time zones, but still same moment in history of the Universe.