Javascript Angular js:Angular ng repeat中的拆分日期和时间参数

Javascript Angular js:Angular ng repeat中的拆分日期和时间参数,javascript,html,angularjs,Javascript,Html,Angularjs,我正在ng repeat中显示一些数据,因此我想将日期显示为三个参数 1.日期 2.每月 3.时间 我将以单个字符串的形式获取日期2016-05-13 16:08:33 <div class="list-expense-menu-item" ng-repeat="notification in notifications"> <h2>{{notification.text}}</h2> <span>Date:{{notification.n

我正在
ng repeat
中显示一些数据,因此我想将日期显示为三个参数

1.日期 2.每月 3.时间

我将以单个字符串的形式获取日期
2016-05-13 16:08:33

<div class="list-expense-menu-item" ng-repeat="notification in notifications">
  <h2>{{notification.text}}</h2>
  <span>Date:{{notification.notif_date}}</span>
</div>

{{notification.text}
日期:{{notification.notif{u Date}}
期望

<span>Month:05</span>
<span>Date:16</span>
<span>Time:16:08</span>
月份:05
日期:16
时间:16:08

如何将单个日期拆分为三个参数???

最好的方法是在显示通知数据之前对其进行转换。您可以对其使用正则表达式,也可以只解析日期,然后使用日期方法

angular.module('app',[]);
有棱角的
.module('应用程序')
.controller('示例',函数($scope){
常量输入数据=[
{text:'some text',notif_date:'2016-05-13 16:08:33'},
{text:'some text',notif_date:'2017-06-13 18:28:33'}
];
$scope.notifications=inputData.map({text,notif_date})=>{
const regexp=/^\d{4}-(\d{1,2})-(\d{1,2})\s*([\d:]*)$/;
const matched=notif_date.match(regexp);
返回{
文本,
月份:匹配[1],
日期:匹配[2],
时间:匹配[3]
};
});
});

{{notification.text}
月份:{{notification.Month}
日期:{{notification.Date}
时间:{{notification.Time}

最好的方法是在显示通知数据之前对其进行转换。您可以对其使用正则表达式,也可以只解析日期,然后使用日期方法

angular.module('app',[]);
有棱角的
.module('应用程序')
.controller('示例',函数($scope){
常量输入数据=[
{text:'some text',notif_date:'2016-05-13 16:08:33'},
{text:'some text',notif_date:'2017-06-13 18:28:33'}
];
$scope.notifications=inputData.map({text,notif_date})=>{
const regexp=/^\d{4}-(\d{1,2})-(\d{1,2})\s*([\d:]*)$/;
const matched=notif_date.match(regexp);
返回{
文本,
月份:匹配[1],
日期:匹配[2],
时间:匹配[3]
};
});
});

{{notification.text}
月份:{{notification.Month}
日期:{{notification.Date}
时间:{{notification.Time}

在控制器中修改notif\u日期,如下所示

 notifications.forEach(function(notification){
   notification.notif_date = new Date(notification.notif_date);
 })
然后在视图中尝试角度日期

  <span>Month:{{notification.notif_date | date:'MM'}}</span>
  <span>Date:{{notification.notif_date | date:'dd'}}</span>
  <span>Year:{{notification.notif_date | date:'yyyy'}}</span>
月份:{{notification.notif_date}日期:'MM'}
日期:{{notification.notif_Date}日期:'dd'}
年份:{{notification.notif_date}日期:'yyyy'}

在控制器中修改notif\u日期,如下所示

 notifications.forEach(function(notification){
   notification.notif_date = new Date(notification.notif_date);
 })
然后在视图中尝试角度日期

  <span>Month:{{notification.notif_date | date:'MM'}}</span>
  <span>Date:{{notification.notif_date | date:'dd'}}</span>
  <span>Year:{{notification.notif_date | date:'yyyy'}}</span>
月份:{{notification.notif_date}日期:'MM'}
日期:{{notification.notif_Date}日期:'dd'}
年份:{{notification.notif_date}日期:'yyyy'}

我假设您使用的是javascript Date()。让我们在controller notification.notif_date=new date(notification.notif_date)中尝试一下,并告诉我它是否有效。我假设您使用的是javascript date()。让我们在controller notification.notif_date=new date(notification.notif_date)中尝试一下,并告诉我它是否有效。