java中utc时间怎么转换为本地时间?

来源:互联网 发布:mac 内录 编辑:程序博客网 时间:2024/05/16 19:43
java utc转本地时间的方法:
1、创建一个格式化时间对象simpleDateFormat,并初始化格式yyyy-MM-dd HH:mm:ss:
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
2、创建时区对象utcZone,获取utc所在的时区
TimeZone utcZone = TimeZone.getTimeZone("UTC");
3、设置utc时区,为转换做准备
simpleDateFormat.setTimeZone(utcZone);
4、获取本地时间,并转换
Date myDate = simpleDateFormat.parse(rawQuestion.getString("AskDateTime"));
5,按照上面的流程就转换本地时间了。
原创粉丝点击