Skip to content
Advertisement

Tag: momentjs

Moment.js and Unix Epoch Conversion

I have a web service that is returning a date as the following string: /Date(1377907200000)/ I use MomentJS to parse this to a moment object. moment(“/Date(1377907200000)/”) => Fri Aug 30 2013 20:00:00 GMT-0400 All of that is fine. But when I call unix() on the object I am given the value 1377907200. This, however, corresponds to Fri Jan 16 1970

Moment.js – how do I get the number of years since a date, not rounded up?

I’m trying to calculate a person’s age using Moment.js, but I’m finding that the otherwise useful fromNow method rounds up the years. For instance, if today is 12/27/2012 and the person’s birth date is 02/26/1978, moment(“02/26/1978”, “MM/DD/YYYY”).fromNow() returns ’35 years ago’. How can I make Moment.js ignore the number of months, and simply return the number of years (i.e. 34)

Advertisement