How can I set a Calendar with UTC time?

后端 未结 1 1757
情深已故
情深已故 2021-02-05 02:39

The posters here say that Date is always in UTC time. However, if I create a Date(), create a Calendar, and set the calendar time with the date, the time remains my local time (

相关标签:
1条回答
  • 2021-02-05 03:17

    java.util.Calendar has a static factory method which takes a timezone.

    Calendar.getInstance(java.util.TimeZone)

    So you can say:

    Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    
    0 讨论(0)
提交回复
热议问题