我想将此GMT时间戳转换为GMT + 13:
2011-10-06 03:35:05
Run Code Online (Sandbox Code Playgroud)
我尝试过大约100种不同的DateFormat,TimeZone,Date,GregorianCalendar等组合来尝试做这个非常基本的任务.
这段代码完成了我对CURRENT TIME的要求:
Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
DateFormat formatter = new SimpleDateFormat("dd MMM yyyy HH:mm:ss z");
formatter.setTimeZone(TimeZone.getTimeZone("GMT+13"));
String newZealandTime = formatter.format(calendar.getTime());
Run Code Online (Sandbox Code Playgroud)
但我想要的是设定时间而不是使用当前时间.
我发现任何时候我都尝试设置这样的时间:
calendar.setTime(new Date(1317816735000L));
Run Code Online (Sandbox Code Playgroud)
使用本地机器的TimeZone.这是为什么?我知道当"new Date()"返回UTC + 0时,为什么当你设置Time以毫秒为单位时,它不再假设时间是UTC?
有可能:
在此先感谢您的帮助:D