Convert Date by TimeZone

后端 未结 2 1861
半阙折子戏
半阙折子戏 2021-01-23 21:40

In that code above I want to transform a Date by the TimeZone of Server (GMT-02:00) to TimeZone from my Device (GMT-03:00). But I Always have the same Date of the server. What I

2条回答
  •  长发绾君心
    2021-01-23 22:08

    What I doing wrong?

    You're assuming that a Date has a time zone to start with. It doesn't. A Calendar does, but a Date is just milliseconds since the Unix epoch. It doesn't know about calendar systems or time zones. It's just a point in time.

    It's not clear what you want to do with the result - but if it's a matter of formatting it for display, just use SimpleDateFormat and set the time zone on that instead.

    I would also strongly recommend that you use Joda Time instead of the built-in types... it's a much more sensible API.

提交回复
热议问题