Parsing date with Joda with time zone

前端 未结 4 1042
清酒与你
清酒与你 2021-01-01 21:25

I have two timestamps which describe the same instant of time in two different formats.

2010-10-03 18:58:07 and 2010-10-03T16:58:07.000+02:00

4条回答
  •  醉酒成梦
    2021-01-01 22:03

    Your two timestamps don't represent the same instant in time (as jambjo already remarked). See Time zone as offsets from UTC on wikipedia.

    Also see the parseDateTime documentation on how it works. If you don't provide any time zone, then the default time zone will be applied (that is Berlin time zone UTC+2 if you are there). So:

    • 2010-10-03 18:58:07 becomes 2010-10-03T18:58:07.000+02:00 (18:58 in Berlin with offset of 2 hours to UTC, that means 16:58 in UTC) as expected.
    • 2010-10-03T16:58:07.000+02:00 stays as it is, because there is a time zone provided (i.e. 16:58 in Berlin with offset of 2 hours to UTC, that means 14:58 in UTC)

    Hope you got the idea. You will need to adjust the times with the withZone method to get the desired results.

提交回复
热议问题