I have a unix timestamp, and I\'m trying to convert it into a calendar date such as MM/DD/YYYY
.
So far, I have this:
moment(timestamp).format('''any format''')
I fixed it like this example.
$scope.myCalendar = new Date(myUnixDate*1000);
<input date-time ng-model="myCalendar" format="DD/MM/YYYY" />
new moment(timeStamp,'yyyyMMddHHmmssfff').toDate()
Moment.js provides Localized formats which can be used.
Here is an example:
const moment = require('moment');
const timestamp = 1519482900000;
const formatted = moment(timestamp).format('L');
console.log(formatted); // "02/24/2018"
This function creates date from timestamp:
function formatDateTime(dateString) {
const parsed = moment(new Date(dateString))
if (!parsed.isValid()) {
return dateString
}
return parsed.format('MMM D, YYYY, HH:mmA')
}