Working with timezones

Dragoljub Ilic asked on July 6, 2017 10:22

Can anyone recommend me some articles about this subject? This is really confusing me. We store application on Azure and timezones are enabled in kentico settings.

I'm comparing results in System -> Macro console. I will present you couple of examples:

  1. Server timezone (utc +01), and site timezone is none:
  • DateTime.Now -> 2h earlier
  • GetSiteDateTime(DateTime.Now) -> 2h earlier

2.Server timezone (utc +01), and site timezone is (utc +01):

  • DateTime.Now -> 2h earlier
  • GetSiteDateTime(DateTime.Now) -> 2h earlier

3.Server timezone (utc +01), and site timezone is (utc +04):

  • DateTime.Now -> 2h earlier
  • GetSiteDateTime(DateTime.Now) -> correct ???

4.Server timezone (utc +00), and site timezone is (utc +01):

  • DateTime.Now -> 2h earlier
  • GetSiteDateTime(DateTime.Now) -> correct

Is this mean that conversion between timezones only works if server time is set up as (UTC +00)?

Thanks, Dragoljub

Correct Answer

Mike Wills answered on July 6, 2017 18:17

Hi Dragoljub,

Your experiment validates what I've experienced. My understanding is that the Kentico server time zone should be set to the time zone of the machine. In Azure, it seems that the servers are set to UTC+00, so I always set the server time zone to UTC+00 and the site time zone to the local time zone of the website owner or audience. This causes the date time values provided by Kentico APIs and macros to be calculated correctly.

Mike

1 votesVote for this answer Unmark Correct answer

Recent Answers


Trevor Fayas answered on July 6, 2017 15:29

Reading from documentation, the priority goes:

User Time Zone > Site Time Zone > Server Time Zone

While DateTime.Now is always the server's time (not necessarily the Kentico's "Server time zone" time, but just the actual physical computer's time), the GetSiteDateTime(DateTime.Now) i believe will be the time in respect to the User/Site/Server.

Bryan created a blog about it here.

One issue with your testing and confusion is that when you do "GetSiteDateTime(DateTime.Now)" i think the server assumes the given parameter (which you pass DateTime.Now) is the time based on the Server Time Zone, not the computer's time zone. So it assumes the time given is in the Server Time Zone's UTC.

So say the Physical Computer is UTC +1, and the time is 8:00 am (UTC+1).

If you set the Server Time to UTC +2, and you pass it the current DateTime.Now, it assumes that 8:00am is the UTC +2 time.

So when you say "My site timezone is UTC +3", it takes the 8:00am as UTC+2 and increases the hour by 1 to make it UTC+3.

I could be wrong, but that seems to be what is occurring.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.