Unable to format default MySQL datetime

The date format you specified is wrong YYYY should be yyyy, look at the documentation for other example.

Additionally, the date string you are trying to format does not match the specification that Angular has.

Date to format either as Date object, milliseconds (string or number) or various ISO 8601 datetime string formats (e.g. yyyy-MM-ddTHH:mm:ss.SSSZ and its shorter versions like yyyy-MM-ddTHH:mmZ, yyyy-MM-dd or yyyyMMddTHHmmssZ). If no timezone is specified in the string input, the time is considered to be in the local timezone.

Wherever you are retrieving the original string from, I suggest you store/try to retrieve it in one of these formats.

Example JSFiddle using a correct format.


You need to convert your date string to something supported by Angular, like ISO 8601 format. You could convert it like this:

$scope.Object.created = new Date($scope.Object.created).toISOString();

Live demo here (click).

To do this on the fly, you need a custom filter. Live demo here (click).

Markup:

<div>{{Object.created | dateToISO | date:'shortDate'}}</div>

JavaScript:

app.filter('dateToISO', function() {
  return function(input) {
    return new Date(input).toISOString();
  };
});

Update:

Here's a simple way to convert your date manually (firefox):

app.filter('badDateToISO', function() {
  return function(badTime) {
    var goodTime = badTime.replace(/(.+) (.+)/, "$1T$2Z");
    return goodTime;
  };
});