forked from angular/code.angularjs.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathangular.filter.date.html
70 lines (67 loc) · 2.77 KB
/
angular.filter.date.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<h1>angular.filter.date</h1>
<fieldset class="workInProgress">
<legend>Work In Progress</legend>
This page is currently being revised. It might be incomplete or contain inaccuracies.
</fieldset>
<h2>Description</h2>
<p>Formats <code>date</code> to a string based on the requested <code>format</code>.</p>
<p><code>format</code> string can be composed of the following elements:</p>
<ul>
<li><code>'yyyy'</code>: 4 digit representation of year e.g. 2010</li>
<li><code>'yy'</code>: 2 digit representation of year, padded (00-99)</li>
<li><code>'MM'</code>: Month in year, padded (01‒12)</li>
<li><code>'M'</code>: Month in year (1‒12)</li>
<li><code>'dd'</code>: Day in month, padded (01‒31)</li>
<li><code>'d'</code>: Day in month (1-31)</li>
<li><code>'HH'</code>: Hour in day, padded (00‒23)</li>
<li><code>'H'</code>: Hour in day (0-23)</li>
<li><code>'hh'</code>: Hour in am/pm, padded (01‒12)</li>
<li><code>'h'</code>: Hour in am/pm, (1-12)</li>
<li><code>'mm'</code>: Minute in hour, padded (00‒59)</li>
<li><code>'m'</code>: Minute in hour (0-59)</li>
<li><code>'ss'</code>: Second in minute, padded (00‒59)</li>
<li><code>'s'</code>: Second in minute (0‒59)</li>
<li><code>'a'</code>: am/pm marker</li>
<li><code>'Z'</code>: 4 digit (+sign) representation of the timezone offset (-1200‒1200)</li>
</ul>
<h2>Usage</h2>
<h3>In HTML Template Binding</h3>
<tt>
<span>{{</span>
date_expression
| date:format<span> }}</span>
</tt>
<h3>In JavaScript</h3>
<tt ng:non-bindable>
angular.filter.date(date, format);
</tt>
<h3>Parameters</h3>
<ul>
<li><tt>date</tt> –
<tt>{(Date|number|string)}</tt>
<tt></tt>
– Date to format either as Date object, milliseconds (string or
number) or ISO 8601 extended datetime string (yyyy-MM-ddTHH:mm:ss.SSSZ).</li>
<li><tt>format</tt> –
<tt>{string=}</tt>
<tt></tt>
– Formatting rules. If not specified, Date#toLocaleDateString is used.</li>
</ul>
<h3>Returns</h3>
<tt>{string}</tt> Formatted string or the input if input is not recognized as date/millis.
<h2>Example</h2>
<doc:example>
<doc:source>
<span ng:non-bindable>{{1288323623006 | date:'yyyy-MM-dd HH:mm:ss Z'}}</span>:
{{1288323623006 | date:'yyyy-MM-dd HH:mm:ss Z'}}<br/>
<span ng:non-bindable>{{1288323623006 | date:'MM/dd/yyyy @ h:mma'}}</span>:
{{'1288323623006' | date:'MM/dd/yyyy @ h:mma'}}<br/>
</doc:source>
<doc:scenario> it('should format date', function(){
expect(binding("1288323623006 | date:'yyyy-MM-dd HH:mm:ss Z'")).
toMatch(/2010\-10\-2\d \d{2}:\d{2}:\d{2} \-?\d{4}/);
expect(binding("'1288323623006' | date:'MM/dd/yyyy @ h:mma'")).
toMatch(/10\/2\d\/2010 @ \d{1,2}:\d{2}(am|pm)/);
});
</doc:scenario>
</doc:example>