javascript - Moment's fromNow returning strange result -


i'm using fromnow in moment , seem getting odd results.

var moment = require('moment');  var months = {     jan: '1', feb: '2', mar: '3', apr: '4',     may: '5', jun: '6', jul: '7', aug: '8',     sep: '9', oct: '10', nov: '11', dec: '12' }  var input = "3 aug 2015, 12:30".replace(/,/g, "").split(' ') var time = input.pop().split(':') var date = input.reverse() var t = date.concat(time);  t[1] = months[t[1]]; t = moment(t);  console.log(t.fromnow()); 

this printing out "in month".

it seems array you're feeding moment (i.e. ["2015", "aug", "3", "12", "30"]) not valid date. if print out t.todate() after assigning moment(t) states "invalid date".

why not doing , let moment parse date properly:

var m = moment("3 aug 2015, 12:30", "dd mmm yyyy, hh:mm"); console.log(m.fromnow());  > in 5 hours 

Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -