我需要使用此处给出的 JSON 中的created_at 并使用 Angular ,我只想打印日期。如何做到这一点?
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":[]}
我已经通过制作过滤器来完成此操作,但它不起作用并且给出了错误的输出
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;
};
});
最佳答案
根据您的需要,您可以使其变得非常简单:
app.filter('format', function () {
return function (item) {
return new Date(item);
};
});
那么在你看来:
{{modelVariable | format | date}}
这将显示2015年6月17日
或者完全跳过过滤器:
$scope.theDate = new Date(2015-06-17 18:16:08);
{{theDate | date}}
关于javascript - 如何仅从 Angular Js中的MySQL数据库日期戳中获取日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30917952/