How to convert dates to UTC format

Summary:

The Dates retrieved from the database will be converted based on the local time zone in both client and server end. Converting the Dates to UTC format will prevent the time offsets difference between server and client time zones.

Solution:

To prevent the Date conversion and to display all the dates in UTC format, the following steps have to be done on both client and server side.

Step 1:

The dates from the database must be returned in UTC format. To do that, set the DateTime Kind property to UTC. Refer to the following code,

[Controller]

Now the Dates will be returned to the view in UTC format.

Step 2:

When the returned dates are parsed in client end using “new Date()” method, it will be converted to client’s time zone. To avoid that, set ej.parseDateInUTC to true. Refer to the following code,