function getSPCurrentTime(webUrl)
{
return $.ajax({
url: webUrl + "/_api/web/RegionalSettings/TimeZone",
method: "GET",
headers: { "Accept": "application/json; odata=verbose" }
}).then(function(data){
var offset = data.d.Information.Bias / 60.0;
return new Date( new Date().getTime() - offset * 3600 * 1000);
});
}
Usage
getSPCurrentTime(_spPageContextInfo.webAbsoluteUrl)
.done(function(value)
{
console.log(value.toUTCString()); // get current SP server time in UTC
})
.fail(
function(error){
console.log(JSON.stringify(error));
});
{
return $.ajax({
url: webUrl + "/_api/web/RegionalSettings/TimeZone",
method: "GET",
headers: { "Accept": "application/json; odata=verbose" }
}).then(function(data){
var offset = data.d.Information.Bias / 60.0;
return new Date( new Date().getTime() - offset * 3600 * 1000);
});
}
Usage
getSPCurrentTime(_spPageContextInfo.webAbsoluteUrl)
.done(function(value)
{
console.log(value.toUTCString()); // get current SP server time in UTC
})
.fail(
function(error){
console.log(JSON.stringify(error));
});
No comments:
Post a Comment