如何设置 java.util.Date 的时区? [英] How to set time zone of a java.util.Date?

查看:39
本文介绍了如何设置 java.util.Date 的时区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经从 String 解析了一个 java.util.Date 但它将本地时区设置为 date 的时区> 对象.

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.

在解析 DateString 中未指定时区.我想设置 date 对象的特定时区.

The time zone is not specified in the String from which Date is parsed. I want to set a specific time zone of the date object.

我该怎么做?

推荐答案

使用 DateFormat.例如,

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");

这篇关于如何设置 java.util.Date 的时区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆