admin管理员组

文章数量:1181479

I am creating a app using angularjs.Here is my code:

$scope.from = $filter('date')(new Date(), 'yyyy-MM-dd hh:mm');

It shows me output like:2016-05-15 06:30 But I want to show like:2016-05-15 18:30

I am creating a app using angularjs.Here is my code:

$scope.from = $filter('date')(new Date(), 'yyyy-MM-dd hh:mm');

It shows me output like:2016-05-15 06:30 But I want to show like:2016-05-15 18:30

Share Improve this question asked May 21, 2016 at 14:28 angularangular 5632 gold badges8 silver badges17 bronze badges 0
Add a comment  | 

3 Answers 3

Reset to default 23

Here is the API https://docs.angularjs.org/api/ng/filter/date:

'yyyy-MM-dd HH:mm'

Us it like this : $filter('date')(new Date(), 'yyyy-MM-dd HH:mm');

check jsfiddle here

Following formats work :

Non-Padded:
If you were to use non padded format like 6:30 or 8:30 then go for 'H'

<div>{{ date_expression | date : 'yyyy-MM-dd H:mm'}}</div> <!-- in HTML -->
$filter('date')(new Date(), 'yyyy-MM-dd H:mm'); //in Controller

Padded:
If you were to use padded format like 06:30 or 08:30 then go for 'HH'

<div>{{ date_expression | date : 'yyyy-MM-dd HH:mm'}}</div> <!-- in HTML -->
$filter('date')(new Date(), 'yyyy-MM-dd HH:mm'); //in Controller

For Further Reference:
https://docs.angularjs.org/api/ng/filter/date

本文标签: javascriptFormat Date and time into 24 hours formatStack Overflow