Convert UTC Date returned from SharePoint API to Local time using JavaScript and C#

SharePoint Online stores all date fields in UTC format and convert it to appropriate time zone whenever it is retrieved by a user.

However when using SharePoint API, the date returned is in UTC format and have to be converted to local time.

Using the JavaScript function below the local time can be returned.

self.toLocalDate = function (utc_date) {
//The getTimezoneOffset() value is in minutes
var offset = new Date().getTimezoneOffset();
//offset will be in minutes. Add/subtract the minutes from your date
return utc_date.setMinutes(utc_date.getMinutes() + offset);

In C#, the function below can be used

Further articles to help understand time zone in SharePoint Online


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s