Javascript 如何按月份和年份正确过滤日期
在我的数据库中,日期安排如下(日/月/年) 我正在使用angularjs模板,并尝试将日期字段排序为(使用月份和年份编号进行排序),如下所示: 但它是按顺序上升的Javascript 如何按月份和年份正确过滤日期,javascript,angularjs,sorting,date,Javascript,Angularjs,Sorting,Date,在我的数据库中,日期安排如下(日/月/年) 我正在使用angularjs模板,并尝试将日期字段排序为(使用月份和年份编号进行排序),如下所示: 但它是按顺序上升的 Date ----------- 10/12/2014 14/12/2015 22/10/2014 Date ---------- 22/10/2014 14/12/2015 10/12/2014 下降为 Date ----------- 10/12/2014 14/12/2015 22/10/2014 Date -------
Date
-----------
10/12/2014
14/12/2015
22/10/2014
Date
----------
22/10/2014
14/12/2015
10/12/2014
下降为
Date
-----------
10/12/2014
14/12/2015
22/10/2014
Date
----------
22/10/2014
14/12/2015
10/12/2014
这是我的密码
<div class="row">
<div class="col-md-12" ng-show="filteredItems > 0">
<table class="table table-striped table-bordered">
<thead>
<th>Date <a ng-click="sort_by('time_stamp');"><i class="glyphicon glyphicon-sort"></i></a></th>
<th>Reference number <a ng-click="sort_by('tran_id');"><i class="glyphicon glyphicon-sort"></i></a></th>
</thead>
<tbody>
<tr ng-repeat="data in filtered = (list | filter:search | orderBy : predicate :reverse) | startFrom:(currentPage-1)*entryLimit | limitTo:entryLimit">
<td>{{data.time_stamp}}</td>
<td>{{data.tran_id}}</td>
</tr>
</tbody>
</table>
</div>
getCustomer.php:
$query="select tran_id,tran_type,sender,receiver,amount,fee,DATE_FORMAT(time_stamp, '%d/%m/%Y') as time_stamp,status from transaction where sender ='demo@gmail.com' or receiver ='demo@gmail.com' order by time_stamp DESC";
//$query="select * from transaction";
$result = $mysqli->query($query) or die($mysqli->error.__LINE__);
$arr = array();
if($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$arr[] = $row;
}
}
# JSON-encode the response
$json_response = json_encode($arr);
// # Return the response
echo $json_response;
如何在您的情况下获得所需的排序
必须将它们设置为日期对象才能正常排序
编辑
如果我正确理解了您的代码,您将在控制器中获取以下数据:
$http.get('ajax/getCustomers.php').success(function(data){
$scope.list = data;
在诊断问题之后,尝试在下一行中执行类似操作:
$scope.list.time_stamp = new Date(data.time_stamp); // convert string date to Date object
我没有测试代码,但我希望它能工作,因为我们知道问题出在哪里
工作打捞器
基于这个假设,我在中创建了功能排序日期,它就像一个符咒
在controller中,我将属性
date
与date
对象关联起来,如date:new date('9/1/2013')
,并在中下了一个命令。我编辑了我的帖子,希望我的想法是切实解决这个问题。您的成功回调是JSON格式的吗,它看起来怎么样?我已经更新了我的帖子。关于我正在使用的信息,请给我一个包含时间戳属性的JSON结构。@arman1991在你的回答中,它不是应该是新的日期而不是新的数据吗?你能粘贴你的JSON回复吗。
$scope.list.time_stamp = new Date(data.time_stamp); // convert string date to Date object