javascript - Having trouble converting /Date(####)/ to MM/dd/yyyy local with MomentJS -
using external api that's sending me dates such as:
/date(1439596800)/ the above date is:
august 30, 2015 using momentjs this:
moment("/date(1439596800)/").format("mm/dd/yyyy"); gets me this:
01/17/1970 :(
i'm aware i'm supposed multiply * 1000 hoping there specific momentjs method.
thank help.
it's rather simple.
your api gives unix timestamp - default, moment(arg) assumes arg passed milliseconds since 1st january 1970.
for converting it, must first remove /date( , )\. i'd use regex strips non-digit characters:
mystring = mystring.replace(/\d/g,''); this leave numbers. now, can run
moment.unix(mystring).format("mm/dd/yyyy");
Comments
Post a Comment