javascript - toISOString() changes datetime value -


i have array of objects.each object in array has date property.i try biggest(the last) date array.

here array:

var sensorsdata = [{   id: 1,   measuredate: "2017-08-20t09:52:32" }, {   id: 2,   measuredate: "2017-08-20t09:54:35" }, {   id: 3,   measuredate: "2017-08-20t09:56:13" }]; 

and here function fetch biggest date array above:

function updatelatestdate(sensorsdata) {   return new date(math.max.apply(null, sensorsdata.map(function(e) {     return new date(e.measuredate);   }))).toisostring(); } 

the result updatelatestdate function is:

2017-08-20t06:56:13.000z 

but strange because, can see no 1 of properties in sensorsdata objects doesn't have date returned updatelatestdate function.

here fiddler.

any idea why updatelatestdate function returns wrong result?

when create date new date(str) creates date object time zone. toisostring() makes 0 utc offset, denoted suffix "z".

here workaround:

var date = new date(e.measuredate) return new date(date.gettime() - date.gettimezoneoffset() * 60000) 

updated fiddler: https://jsfiddle.net/xf5jmll6/7


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -