Tags

, ,

I often used with SharePoint custom forms and in general I based my development on SharePoint JSOM. Working with it, I am often requested to update date and time fields using JSOM. But there is a small issue with it.

var dt = new Date();
item.set_item(dt);

The code above is with working, with an exception. It converts the date to GMT timezone. If my timezone is GMT + 2, recorded date will have 2 hours less then I have specified. The workaround is to convert the date into formatted string.

var dt = new Date();
item.set_item(dt.format('yyyy-MM-ddTHH:mm:ssZ'));

Date format function is provided by MicrosoftAjax, which is included by default.

Advertisements