I'm having trouble converting a timestamp using moment.js from a json data set. When I try to use
moment.format('MMMM Do YYYY, H:mm:ss')
, the output is showing something like May 25th 2361, 0:00:00
for the timestamp 12351223423
. This seems to happen for all timestamps I've tested so far. Does anyone know why it doesn't display the correct time and how can I fix this?
Here's an excerpt from my Angular controller:
$scope.timeFormat = function(timestamp) {
var dt = moment.unix(timestamp);
if(++recheckDate % 25 == 0)
{
// predefined variables
today = moment().startOf('day');
yesterday = moment().subtract(1, 'days');
}
if(dt.startOf('day').isSame(today))
return dt.format('[Today], H:mm:ss');
if(dt.startOf('day').isSame(yesterday))
return dt.format('[Yesterday], H:mm:ss');
return dt.format('MMMM Do YYYY, H:mm:ss');
};
Below is the HTML code snippet (trimmed down, assuming the controller and app setup are functional for other fields):
<div ng-repeat="item in data">
<span class="time">{{ timeFormat(item.time) }}</span>
</div>
UPDATE: You can view an online demo here. The error still persists. The source code can be found on GitHub.