信念树下
--梦想只是不能实现的,想要实现就要有计划。
posts - 5,comments - 0,trackbacks - 0
 1import java.util.TimeZone;
 2import java.util.Date;
 3import java.text.DateFormat;
 4
 5public class ForTest {
 6
 7public static void main(String[] args) {
 8
 9DateFormat dateFormatterChina = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,DateFormat.MEDIUM);//格式化输出
10TimeZone timeZoneChina = TimeZone.getTimeZone("Asia/Shanghai");//获取时区
11dateFormatterChina.setTimeZone(timeZoneChina);//设置系统时区
12Date curDate = new Date();//获取系统时间
13
14System.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 三角形 阅读(790) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: