javascript - date time issue moment -


sometimes timestamp more 10 digits. using moment js function is:

moment.unix(timestamp).format('yyyy-mm-dd hh:mm') 

when 10 digits long giving me perfect answer. when more 10 digits. don't know why giving wrong year.

sample: correct: 1433167001 gives me 2015-06-01 13:56 incorrect: 1433287744646 gives me date: 47389-01-29 12:37

i tried /1000 not working

code

 - var timestamp =''                                 - if (typeof(res[j]['timestamp']) !== 'undefined'){                                     - timestamp = math.floor(res[j]['timestamp']);                                     - if (timestamp.length > 10) {                                         - timestamp = math.floor(timestamp/1000)                                     - }                                 -}                                  tr                                     td #{index++}                                     td #{results[i]['userinfo']['username']}                                     td #{typename}                                     td #{value}                                     td #{moment.unix(timestamp).format('yyyy-mm-dd hh:mm')} 

the above code in jade.

traditionally, term "unix timestamp" refers number of seconds have elapsed since midnight, january 1st 1970 utc (not counting leap seconds).

var m = moment.unix(numberofseconds); 

however, javascript , many other platforms define timestamps in terms of milliseconds instead of seconds.

var m = moment(numberofmilliseconds); 

it important understand source of data know whether timestamps in terms of seconds or milliseconds. if guess based upon number of digits, excluding range of possible values.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -