Reputation: 451
I get different output based on how values are passed to moment
. How are they different?
var moment = require('moment');
var aa = "1392018037000";
var bb = "1392057925366";
console.log(moment(aa).from(bb));
console.log(moment(1392018037000).from(1392057925366));
output:
a few seconds ago
11 hours ago
Upvotes: 0
Views: 98
Reputation: 6346
This is a string:
var aa = "1392018037000";
This is an integer:
var aa = 1392018037000;
According to moment documentation:
Similar to new Date(Number), you can create a moment by passing an integer value representing the number of milliseconds since the Unix Epoch (Jan 1 1970 12AM UTC).
So proper way would be to use an integer. String behaves differently in Javascript, mostly because it would need to call parseInt function, and that has different way of parsing integers.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt
Upvotes: 1