在 ServletContextListener 初始化方法中,我们将时区设置为
public void contextInitialized(ServletContextEvent event) {
TimeZone.setDefault(TimeZone.getTimeZone("GMT+00:00"));
}
但是当我检查 servlet 中的时区信息并过滤时,时区发生了变化。 任何人都知道可能是什么原因。
谢谢
最佳答案
看,我已经上课了
public class TimeZ {
public static void main(String args[]){
System.out.println("1."+TimeZone.getTimeZone("GMT+00:00"));
System.out.println("2. "+TimeZone.getDefault());
TimeZone.setDefault(TimeZone.getTimeZone("GMT+00:00"));
System.out.println("3. "+TimeZone.getDefault());
System.out.println("4. "+TimeZone.getTimeZone("GMT+00:00"));
}
}
我的输出是:
1.sun.util.calendar.ZoneInfo[id="GMT+00:00",offset=0,dstSaving...
2. sun.util.calendar.ZoneInfo[id="Asia/Calcutta",offset=19800000,...
3. sun.util.calendar.ZoneInfo[id="GMT+00:00",offset=0,dstSaving...
4. sun.util.calendar.ZoneInfo[id="GMT+00:00",offset=0,dstSaving...
explanation: by default my timezone is india. It's going to return the timezone of the JVM TimeZone.getDefault() is executed on. So if the application is running on a server in India, it will be something like "Asia/Calcutta" .when you set default timezone to GMT, it changes its timezone to GMT zone. thats simple...
关于java - google appengine - 时区已更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42532353/