Wednesday, July 13, 2016

how to get server datetime in Sharepoint 2013 usign ECMAScript or Client Side

My client machine and server machine 

function getTimeZoneAndServerDateTime() {

    var context = SP.ClientContext.get_current();
    var web = context.get_web();
    var timeZone = web.get_regionalSettings().get_timeZone();
    context.load(timeZone);
    context.executeQueryAsync(
    function onSucceeded() {
        var info = timeZone.get_information();
        var offset = (info.get_bias() + info.get_daylightBias()) / 60.0;
        var serverDateTimeNow = new Date(new Date().getTime() - offset * 3600 * 1000).toISOString();
        console.log("serverDateTimeNow: " + serverDateTimeNow);
    },
     Failure
    );

}

function Failure() {
    alert("error");
}

No comments:

Post a Comment