The timezone set in SharePoint Online is EST and when it is being saved to SharePoint using CSOM/ECMA script from location with UTC +5:30 timezone the date is reduced. Everytime we edit the time is reduced. What is the right way to save date to SP using CSOM? SharePoint OOTB save it as per the local timezone
4 Answers
You can use the JavaScript methods like getUSTDate()
, getUSTHour()
, getUSTMinute()
, getUSTMinute()
to Get the Current UST date and Time. Please refer the Link
Or you have to convert it manually using the below code
function convertToServerTimeZone(){
//EST
offset = -5.0
clientDate = new Date();
utc = clientDate.getTime() + (clientDate.getTimezoneOffset() * 60000);
serverDate = new Date(utc + (3600000*offset));
alert (serverDate.toLocaleString());
}
-
but when we save to list it changes the time . Is there a format with which we can save using CSOM to list– JinxedApr 9, 2016 at 0:38
-
Refer this Link. This would be useful sharepoint.stackexchange.com/questions/103698/… Apr 11, 2016 at 5:12
-
You can use the SP.RegionalSettings.timeZone
property from sp.js to get the server timezone.
The LCID for the current context can be gotten directly from 2 variables:
//as an int
var lcid =_spPageContextInfo.currentLanguage;
// or as a string
var lcid = SP.Res.lcid;
I don't have privileges to comment so adding it as an answer. SharePoint stores the dates internally as UTC, so when you add any data you need to manually convert the time to UTC otherwise when added from a different time zone you'll always see a time difference.
You can try out SP.TimeZone.localTimeToUTC which actually converts your date-time as per the UTC DateTime.
var isoDate = SP.TimeZone.localTimeToUTC(yourdatefield).toString();
Refer How to: Set a date with correct time in a SharePoint list item
All the best!!
Sharing is caring....