how to take the date only from a MySQL database timestamp in angularJs

advertisements

i need to use the created_at from the JSON given here and using angular , i want just the date to print. How to do that?

files":{"65":[{"id":5,"ticket_id":65,"file_name":"1434545168_South Park s10e10 - Miss Teacher Bangs a Boy _ 480p UNCENSORED x264 NIT158.srt","file_size":"30893","file_url":"http:\/\/localhost\/levigo\/storage\/app\/1434545168_South Park s10e10 - Miss Teacher Bangs a Boy _ 480p UNCENSORED x264 NIT158.srt","**created_at":"2015-06-17 18:16:08"**},{"id":6,"ticket_id":65,"file_name":"1434545196_6croMg5xi.png","file_size":"65412","file_url":"http:\/\/localhost\/levigo\/storage\/app\/1434545196_6croMg5xi.png","created_at":"2015-06-17 18:16:36"},{"id":7,"ticket_id":65,"file_name":"1434545214_6croMg5xi.png","file_size":"65412","file_url":"http:\/\/localhost\/levigo\/storage\/app\/1434545214_6croMg5xi.png","created_at":"2015-06-17 18:16:54"}],"66":[]}

I have done this by making my filter but it is not working and given wrong ouput

myApp.filter('format', function () {
      return function (item) {
           var t = item.split(/[- :]/);
       var d = new Date(t[0], t[1]-1, t[2], t[3], t[4], t[5]);
       var time=d.getTime();
               return time;
      };
    });


Depending on what you want you could keep it extremely simple:

app.filter('format', function () {
      return function (item) {
        return new Date(item);
      };
    });

then in your view:

{{modelVariable | format | date}}

This will show Jun 17, 2015

plunker


Alternatively skip the filter altogether:

$scope.theDate = new Date(2015-06-17 18:16:08);

{{theDate | date}}