Reputation: 14824
I have a redis stored timestamp when I get it, it looks like this:
1454803149444
Then when I try to do:
i.text-muted.createdAtPost= moment(post.timestamp).format("MM/DD/YY @ h:mm:ss") // Jade Template
I get
Invalid Date
But if I take the same integer, and go moment(1454803149444).format(h:mm:ss")
I get 05/21/54 @ 12:00:00
Any information would be great thanks.
Upvotes: 3
Views: 2960
Reputation: 2670
I had the same problem. What I did was
let time = post.timestamp / 1000;
let formatted = moment.unix(time).format("MM/DD/YY @ h:mm:ss");
I have no idea why this works. I tried forcing the value into an integer and still got invalid date. I hard coded the value that was console logged and it worked, like in your case. For some reason dividing it by 1000 and calling it a unix timestamp works fine. Seems like a bug to me.
Upvotes: 8
Reputation:
What value does timestamp
pass?
Did you check that?
If it has a specific format you need to set it as:
moment(post.timestamp, 'YYYY/DD/MM').format("MM/DD/YY @ h:mm:ss")
Upvotes: 0