appengine TimeZone changed

2,174 views
Skip to first unread message

Yashavanta S B

unread,
Mar 3, 2017, 11:48:41 PM3/3/17
to Google App Engine
Hey,

In ServletContextListener initialization method we are setting the JVM Time Zone as

public void contextInitialized(ServletContextEvent event) {
TimeZone.setDefault(TimeZone.getTimeZone("GMT+00:00"));
}

But when i check the Time Zone information in servlets and filters the Time Zone got changed.

log.info("TimeZone : " + TimeZone.getDefault());

What might be the reason? 

Thanks

Adam (Cloud Platform Support)

unread,
Mar 4, 2017, 5:14:33 PM3/4/17
to Google App Engine
The timezone in App Engine is always set to UTC and cannot be changed. You'll need to convert between UTC and the timezone you wish to use. You can refer to one of the numerous existing threads on the subject for more background.

Yashavanta S B

unread,
Mar 6, 2017, 12:20:22 AM3/6/17
to Google App Engine
Thanks for the reply.

What about in development server? Can we change the app-engine time zone in development server? Because we want to test date behavior for different time zones and we are facing the difficulties in testing the different time zone dates.

Anastasios Hatzis

unread,
Mar 6, 2017, 2:31:11 AM3/6/17
to Google App Engine
There are really good reasons why an app should not change timezones on the server and why to store all datetimes in UTC. This is especially true in all distributed systems. The app must be designed in a way that it can convert from/to UTC while exchanging data with the outside world or only where it really needs to calculate with local timezones. I don't understand, why you would want to test a different date behavior in development server. Even if it would be possible in dev server, you can be sure that the app will break once it is deployed.

Yashavanta S B

unread,
Mar 7, 2017, 12:30:20 AM3/7/17
to Google App Engine
Thank you for the information. But my question is - why it is showing the different time zone in servlets and filters, even when we are setting the default time zone to GMT+00:00. The issue is with the local development server. But in the production server it is fine.

Adam (Cloud Platform Support)

unread,
Mar 7, 2017, 2:29:54 PM3/7/17
to Google App Engine
The development server time zone also defaults to UTC, so the solution is to not try to change it to anything and instead write your code to work the same way in production and development (that is, to deal with times that are in UTC).

Nicholas (Google Cloud Support)

unread,
Mar 10, 2017, 3:31:11 PM3/10/17
to Google App Engine
I wholeheartedly agree with the recommendations of the community posted here.  I will nevertheless reach out to the documentation team to see if and where this behavior can be documented.

Yashavanta S B

unread,
Mar 10, 2017, 11:58:32 PM3/10/17
to Google App Engine
The issue is still there, even without setting the default time zone to GMT+00:00 in the ServletContextLIstener. Servlet is showing different timezone in development server.

Adam (Cloud Platform Support)

unread,
Mar 13, 2017, 12:28:54 PM3/13/17
to Google App Engine
Try adding -Duser.timezone=UTC to your list of Maven command line arguments when starting the development server. If the timezone is different this looks like it could be a recurrence of an issue that was reported 4 years ago on Stack Overflow, but should have been fixed since then. It may also help to know what version of the Cloud SDK and App Engine SDK you're using.
Reply all
Reply to author
Forward
0 new messages