JavaScript date formatting in string for JSON DeSeriailization

I am using the .NET NewtonSoft JSON serialization library, and it expects date fields in this format:

"UpdateTimestamp":"\/Date(1280408171537+0100)\/"

Does anyone know how I can format a javascript date object in this format?

+3
source share
2 answers

try the following:

var UpdateTimestamp = "" \ / Date ("+ (new Date (). getTime ()) +" +0100) \ / ";
0
source

The format looks like unix time. You can get this using the valueOf method of a Date object. I imagine that the part after the + sign is the time zone offset. You can get this with the getTimezoneOffset method.

- , Date:

Date.prototype.getTimestamp=function(){
    var to = this.getTimezoneOffset()/60;
    to = (to < 10) ? "0"+to: to;
    return this.valueOf()             //get the unix time 
       +"+"+to+"00";
}

** , getTime, jcubic.

0

Source: https://habr.com/ru/post/1757146/


All Articles