DroopyTersen
12/5/2016 - 4:30 PM

CreateSPChangeToken.js

var createChangeToken = function(date,listId) {
    //Change token format:
    // http://sharepoint.stackexchange.com/questions/194152/sharepoint-sharepoint-online-how-can-i-create-changetoken-without-using-msft-li
    
    // The tricky part is the .NET ticks (micrsseconds since 1/1/1)    
    // Got the static number by running C#:
    // (DateTime.MinValue.Subtract(new DateTime(1970, 1, 1))).TotalMilliseconds
    // Add the static milliseconds since 1/1/1 to the JS milliseconds since 1/1/1970
    console.log(date);
    console.log(new Date());
    var milliSecondsSince111 = 62135596800000 + date.getTime();
    // "Convert" to microseconds.  No point actually doing math here though right?
    var microseconds = milliSecondsSince111 + "0000";
    return { "StringValue": `1;3;${listId};${microseconds};-1`};
}