Javascript 更改angularjs中的日期时间格式
我从api中获取日期和时间。我想更改日期和时间格式 我越来越喜欢这个“2016-05-12”,“07:17:35” 更改格式,如2016年5月12日下午7:30:Javascript 更改angularjs中的日期时间格式,javascript,jquery,angularjs,html,Javascript,Jquery,Angularjs,Html,我从api中获取日期和时间。我想更改日期和时间格式 我越来越喜欢这个“2016-05-12”,“07:17:35” 更改格式,如2016年5月12日下午7:30: <table class="table"> <thead> <tr> <th>Time</th> <th>Place</th> </tr> &l
<table class="table">
<thead>
<tr>
<th>Time</th>
<th>Place</th>
</tr>
</thead>
<tbody ng-repeat="l in dataget">
<tr>
<td>{{l['time']}}</td>
<td>{{l['place']}}</td>
</tr>
</tbody>
</table>
时间
放置
{{l['time']}
{{l['place']}
如上所述,您需要这样编写:
{{yourDate | date:'dd MMM yyyy hh:mm a'}
。
结果将是2016年5月12日下午7:30使用日期过滤器
<table class="table" ng-repeat="a in list_alerts">
<thead><tr>
<th>Time</th>
<th>Place</th>
</tr>
</thead>
<tbody ng-repeat="l in dataget">
<tr>
<td>{{l['time']| date : format}}</td>
<td>{{l['place']}}</td>
</tr>
</tbody>
</table>
时间
放置
{{l['time']|日期:格式}
{{l['place']}
该格式应替换为一个可能接受的值,对于显示所需输出的格式,请检查angular api中的可能值:
下面是一个使用“短”格式的示例:
<table class="table" ng-repeat="a in list_alerts">
<thead><tr>
<th>Time</th>
<th>Place</th>
</tr>
</thead>
<tbody ng-repeat="l in dataget">
<tr>
<td>{{l['time']| date : 'short'}}</td>
<td>{{l['place']}}</td>
</tr>
</tbody>
</table>
时间
放置
{{l['time']|日期:'short'}
{{l['place']}
使用日期:在带有管道符号的对象之后设置格式
我认为这很有帮助
app.controller("myCtrl", function($scope,$filter) {
$scope.dateString = '"2016-05-12","07:17:35"';
$scope.finalFormat = $filter('date')(new Date($scope.dateString.substring(1,11) +" "+ $scope.dateString.substring(14,22)),'dd-MMM-yyyy hh:mm a');
});
检查日期格式并按如下方式使用:
{{your_date | date:'dd-MMM-yyyy hh:mm a'}}
在这里玩吧。
在您的案例中使用它:
<table class="table">
<thead>
<tr>
<th>Time</th>
<th>Place</th>
</tr>
</thead>
<tbody ng-repeat="l in dataget">
<tr>
<td>{{l['time'] | date:'dd-MMM-yyyy hh:mm a'}}</td>
<td>{{l['place']}}</td>
</tr>
</tbody>
时间
放置
{{l['time']|日期:'dd-MMM-yyyy hh:mm a'}
{{l['place']}
*controller.js
var myApp = angular.module('myApp', []);
myApp.filter('datetime', function($filter)
{
return function(input)
{
if(input == null){ return ""; }
var _date = $filter('date')(new Date(input),
'MMM dd yyyy - HH:mm:ss');
return _date.toUpperCase();
};
});
HTML格式的
<div ng-app="sampleapp">
<table class="table">
<thead>
<tr>
<th>Time</th>
<th>Place</th>
</tr>
</thead>
<tbody ng-repeat="l in dataget">
<tr>
<td>{{l['time'] | datetime}}</td>
<td>{{l['place']}}</td>
</tr>
</tbody>
时间
放置
{{l['time']|datetime}
{{l['place']}
你的日期是这样的吗?“2016-05-12”,“07:17:35”,“或
“2016-05-12 07:17:35”
这样?我是这样的[“2016-05-12”,“07:17:35”]我想从ng重复