1
import java.util.TimeZone;
2
import java.util.Date;
3
import java.text.DateFormat;
4
5
public class ForTest
{
6
7
public static void main(String[] args)
{
8
9
DateFormat dateFormatterChina = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,DateFormat.MEDIUM);//格式化输出
10
TimeZone timeZoneChina = TimeZone.getTimeZone("Asia/Shanghai");//获取时区
11
dateFormatterChina.setTimeZone(timeZoneChina);//设置系统时区
12
Date curDate = new Date();//获取系统时间
13
14
System.out.println(dateFormatterChina.format(curDate));
15
}
16
}
正常情况下会与本机时间相差8小时,原因是注册表里面的时区设置问题。
解决:
找到原有的注册表并修改对应的地方
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\China Standard Time]
“Display“=“(GMT+08:00) 北京,重庆,香港特别行政区,乌鲁木齐“
“Dlt“=“中国夏季时间“
“Std“=“中国标准时间“
“MapID“=“-1,75“
“Index“=dword:000000d2
“TZI“=hex:20,fe,ff,ff,00,00,00,00,c4,ff,ff,ff,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
posted on 2010-10-25 21:01
三角形 阅读(795)
评论(0) 编辑 收藏