How to set time zone of a java.util.Date?

后端 未结 10 2013
我寻月下人不归
我寻月下人不归 2020-11-22 01:45

I have parsed a java.util.Date from a String but it is setting the local time zone as the time zone of the date object.

The ti

10条回答
  •  天命终不由人
    2020-11-22 01:50

    Use DateFormat. For example,

    SimpleDateFormat isoFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    isoFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
    Date date = isoFormat.parse("2010-05-23T09:01:02");
    

提交回复
热议问题