I'm using this filter
Vue.filter("toDate", function (value) {
if (value) {
return moment(Date(value)).format("yyyy-MM-DD HH:mm");
}
});
The value content is 1529416634
So the Value should be 2018-06-19 15:57
But when I pass the date
return moment(value).format() //1970-01-18 17:50
And with the Date() function
return moment(Date(value)).format("yyyy-MM-DD HH:mm"); //2021-09-18 11:16
It gives me the date of today.
What Am I doing wrong?
moment and Date takes the time in the number of milliseconds since the Unix Epoch (Jan 1 1970 12AM UTC).
You are currently passing it as the number of seconds since the Unix Epoch.
You can do
return moment(value * 1000).format() //2018-06-19T14:57:14+01:00
or
return moment.unix(value).format() //2018-06-19T14:57:14+01:00
or
return moment(new Date(value * 1000)).format() //2018-06-19T14:57:14+01:00