$(document).ready(function() {
var value = $("#unixtime").val(); //this retrieves the unix timestamp
var dateString = moment(value, 'MM/DD/YYYY', false).calendar();
alert(dateString);
});
There is a strict mode and a Forgiving mode.
While strict mode works better in most situations, forgiving mode can be very useful when the format of the string being passed to moment may vary.
In a later release, the parser will default to using strict mode.
Strict mode requires the input to the moment to exactly match the specified format, including separators. Strict mode is set by passing true as the third parameter to the moment function.
A common scenario where forgiving mode is useful is in situations where a third party API is providing the date, and the date format for that API could change.
Suppose that an API starts by sending dates in 'YYYY-MM-DD' format, and then later changes to 'MM/DD/YYYY' format.
In strict mode, the following code results in 'Invalid Date' being displayed:
moment('01/12/2016', 'YYYY-MM-DD', true).format()
"Invalid date"
In forgiving mode using a format string, you get a wrong date:
moment('01/12/2016', 'YYYY-MM-DD').format()
"2001-12-20T00:00:00-06:00"
another way would be
$(document).ready(function() {
var value = $("#unixtime").val(); //this retrieves the unix timestamp
var dateString = moment.unix(value).calendar();
alert(dateString);
});