How to make Date locale-independent?

后端 未结 5 1860
我在风中等你
我在风中等你 2021-01-06 10:13

I have a db, that stores dates in OleDateTime format, in GMT timezone. I\'ve implemented a class, extending Date in java to represent that in class

5条回答
  •  隐瞒了意图╮
    2021-01-06 10:28

    A Date is locale-independent, always using GMT timezone. It's just a wrapper around a millisecond timestamp in GMT (more correctly: UTC).

    The only things in Date that are timezone dependant are the deprecated methods like getDay() - that's why they're deprecated. Those use the default time zone. The correct thing to do is to avoid using those deprecated methods - not to set the default timezone to UTC! That could cause problems elsewhere, and you can't prevent other parts of the code from setting the default timezone to something else.

提交回复
热议问题