java - google appengine - 时区已更改

标签 java date google-app-engine timezone

在 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/

相关文章:

java - 如何在 Java 6 中等效于 Collectors.groupingBy?

java - jstack 抛出异常询问核心

java - HttpClient 向 Jenkins 进行身份验证

javascript - 使用javascript获取日期字符串的日期

bash - 更新文件中多个日期的日期格式

google-app-engine - AppEngine 特定版本 HTTPS 证书错误

java - 访问类中的字段

asp.net - 需要一个免费的 ASPX 日期选择器

java - 谷歌驱动器 dredit 错误 java.lang.NoSuchMethodError : com. google.api.client.http.HttpRequestFactory.buildRequest

google-app-engine - 如何在 python GAE 中从 PayPal 沙箱上线?