Applet客户端程序如何获取本地时区?
无趣 2007-05-21 11:35:18 最近做一个国际化的项目,涉及到时区转换。服务端传过来格林威治时间戳(SOCKET通信),在不同时区的客户端,要求转换为各自本地时间显(还要考虑夏令时)。问题是:不知如何运行时获取本地时区,我试过TimeZone.getDefault(),得到的不是本地时区。
//假设now是服务器传过来的GMT时间
Date now=new Date();
//获得东8区的formatter
DateFormat gmt08Formatter = DateFormat.getDateTimeInstance();
//如能获取本地时区相对GMT的偏移量,替换下面08:00即可
TimeZone timezone = TimeZone.getTimeZone("GMT+08:00");
gmt08Formatter.setTimeZone(timezone);
//获得格式化后的东八区时间
String gmt08DateTime = gmt08Formatter.format(now);
System.out.println(gmt08DateTime);
请大侠指点,谢谢。