在angularjs中,我们使用日期过滤器提供不同类型的日期格式。下表显示了angularjs中日期过滤器可用的不同类型的日期格式。
| Format | Expression | Result |
|---|---|---|
|
yyyy (Year) |
{{sampledate | date:"yyyy" }} |
2016 |
|
yy (Year) |
{{sampledate | date:"yy" }} |
16 |
|
y (Year) |
{{sampledate | date:"y" }} |
2016 |
|
MMMM (Month) |
{{sampledate | date:"MMMM" }} |
February |
|
MMM (Month) |
{{sampledate | date:"MMM" }} |
Feb |
|
MM (Month) |
{{sampledate | date:"MM" }} |
02 |
|
M (Month) |
{{sampledate | date:"M" }} |
2 |
|
dd (Date) |
{{sampledate | date:"dd" }} |
28 |
|
d (Date) |
{{sampledate | date:"d" }} |
28 |
|
EEEE (Day) |
{{sampledate | date:"EEEE" }} |
Sunday |
|
EEE (Day) |
{{sampledate | date:"EEE" }} |
Sun |
|
HH (24 Hours Format) |
{{sampledate | date:"HH" }} |
19 |
|
H (24 Hours Format) |
{{sampledate | date:"H" }} |
19 |
|
hh (12 Hours Format) |
{{sampledate | date:"hh" }} |
07 |
|
h (12 Hours Format) |
{{sampledate | date:"h" }} |
7 |
|
mm (Minute) |
{{sampledate | date:"mm" }} |
16 |
|
m (Minute) |
{{sampledate | date:"m" }} |
16 |
|
sss (Milli Seconds) |
{{sampledate | date:"sss" }} |
501 |
|
ss (Seconds) |
{{sampledate | date:"ss" }} |
45 |
|
s (Seconds) |
{{sampledate | date:"s" }} |
45 |
|
a (AM/PM) |
{{sampledate | date:"a" }} |
PM |
|
Z (TimeZone) |
{{sampledate | date:"Z" }} |
0530 |
|
ww (Week of year) |
{{sampledate | date:"ww" }} |
09 |
|
w (Week of year) |
{{sampledate | date:"w" }} |
9 |
|
medium |
{{sampledate | date:"medium" }} |
Feb 28, 2016 7:32:55 PM |
|
short |
{{sampledate | date:"short" }} |
2/28/16 7:33 PM |
|
fullDate |
{{sampledate | date:"fullDate" }} |
Sunday, February 28, 2016 |
|
longDate |
{{sampledate | date:"longDate" }} |
February 28, 2016 |
|
mediumDate |
{{sampledate | date:"mediumDate" }} |
Feb 28, 2016 |
|
shortDate |
{{sampledate | date:"shortDate" }} |
2/28/16 |
|
mediumTime |
{{sampledate | date:"mediumTime" }} |
7:37:34 PM |
|
shortTime |
{{sampledate | date:"shortTime" }} |
7:37 PM |
<body ng-app="AngulardateApp">
<div ng-controller="datectrl">
Enter Number: <input type="text" ng-model="sampledate" style="width:400px" /><br /><br />
Date with short expression:{{sampledate | date:"short" }}<br /><br />
Date with mediumDate expression: {{sampledate | date : "mediumDate"}} <br /><br />
Date with yyyy-mm-dd hh:mm:ss expression: {{sampledate | date : "yyyy-mm-dd hh:mm:ss" : 0}} <br /><br />
Date with yyyy-mm-dd hh:mm:ss expression: {{sampledate | date : "dd/mm/yyyy 'at' hh:mma" : 0}}
</div>
</body>
JavaScript代码:<script>
var app = angular.module("AngulardateApp", []);
app.controller("datectrl", function ($scope) {
$scope.sampledate = new Date();
});
</script>
热门推荐:
0