Solutions to Date-Time Issue between Server Clients at different Timezone

Abhishek Mallick
3 min readFeb 18, 2020

--

Disclaimer: This is an illustration. Should not be compared with reality

After investing a lot of time in solving the date-time difference problem between Server and Clients due to them being at different Timezone, I understood a few things which I would share with you.

  1. You can’t control the client’s timezone.
  2. You can only control your server-side timezone.
  3. You can’t force your client to accept your specific date-time.

So there are two solutions I came up with:

Solution 1: Ask for a preferred timezone from client

In this process, you ask a preferred timezone to the client and keep it stored in your system. While fetching data back to the client we make a wrapper which accepts the stored date-time with server timezone, converts to the clients preferred timezone and then send it to the client.

Solution 2: Send the date-time with timezone to client

In this process when you send the date-time back to the client you attach the server timezone with it. At the client-side, you can take help of some libraries like Moment.js, JQuery, etc. to convert to the client’s system timezone automatically.

Now a few questions that you may also have like I had:

Q. What is the server timezone of stored date-time in the database if solution 1 is applied?

Ans. Well, I always prefer to use the UTC timezone while storing data. As it never creates a problem due to no Daylight Savings Time (DST) attached.

Q. When to use which solution?

Ans. Well, it’s upon the data we are dealing with:

  • Dealing with data that is going to be in use for many years from now better go for solution 1.
  • Short term data to be used for a year or two go for solution 2.

Q. How to convert date-time in solution 1?

Ans. We can use some online services API from companies like Google, Microsoft, etc.

Else if you are using windows server for hosting your application you can use windows TimezoneInfo class in your c# application. For this, you have to keep your auto-update of time always on.

Q. Benefits of using online service or windows TimezoneInfo class?

Ans. Following are the Benefits:

  • The date-time difference between server and client will be taken care of automatically.
  • Daylight Savings Time (DST) update based conversion will be accurate.
  • Less Manual work in managing the conversion for a different place on earth.

Q. Example for daylight savings time causing a problem in manual?

Ans. Well take this example:

Suppose that in a country “Apple” the daylight savings was supposed to get off on 15th May in 2017 due to which you programmed in your application manually to do so. But on 13th May 2017, it was decided due to the change in the lunar phase that the date will be extended by 10 days. Now you have to make that change again else the system will start taking wrong date-time.

Now think this can happen with many countries at the same or different time so all there data will need an update.

Here the service-based or Windows TimezoneInfo class takes care of it automatically as they get updated by the service providers automatically putting less load on you.

(The above example is from a live case that happened in real only the names and dates are changed here)

Now, these were the 2 ways I handled the problem of date-time in my application.

Would surely like to hear from you how you took care of yours.

--

--

Abhishek Mallick

Innovator, Visionary, Lead, Researcher and Creator. I work on multiple technologies with multi-level of complexity.