【问题标题】:how to take the date only from a MySQL database datestamp in angular Js如何仅从 angularJs 中的 MySQL 数据库时间戳中获取日期
【发布时间】:2015-09-04 05:52:43
【问题描述】:

我需要使用此处给出的 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;
      };
    });

【问题讨论】:

  • 过滤器给出什么输出?

标签: javascript json angularjs laravel


【解决方案1】:

根据你的需要,你可以让它变得非常简单:

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

那么在你看来:

{{modelVariable | format | date}}

这将显示Jun 17, 2015

plunker


或者完全跳过过滤器:

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

{{theDate | date}}

【讨论】:

    【解决方案2】:
    return function (item) {
               var t = item // this nothing but created date "2015-06-17 18:16:08"
           var d = new Date(t); // i.e var d = new Date("2015-06-17 18:16:08")
           var time= d.getTime(); 
           time = d.getDate()+"-"+(d.getMonth()+1)+"-"+d.getFullYear();     
                   return time; // return milliseconds
          };
    

    JS FIDDLE LINK

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-12
      • 2012-07-10
      • 1970-01-01
      • 1970-01-01
      • 2021-07-27
      • 1970-01-01
      • 2012-12-16
      • 2023-03-22
      相关资源
      最近更新 更多