forked from dnasir/angular-dateParser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.html
211 lines (187 loc) · 8.99 KB
/
demo.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<!doctype html>
<html ng-app="dateParser">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Angular DateParser Demo</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.2/css/bootstrap.css" />
<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/SyntaxHighlighter/3.0.83/styles/shCore.css">
<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/SyntaxHighlighter/3.0.83/styles/shThemeDefault.css">
<style type="text/css">
.bs-docs-example {
position: relative;
margin: 15px 0;
padding: 39px 19px 14px;
background-color: #fff;
border: 1px solid #ddd;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
}
.bs-docs-example:after {
content: "Example";
position: absolute;
top: -1px;
left: -1px;
padding: 3px 7px;
font-size: 12px;
font-weight: bold;
background-color: #f5f5f5;
border: 1px solid #ddd;
color: #9da0a4;
-webkit-border-radius: 4px 0 4px 0;
-moz-border-radius: 4px 0 4px 0;
border-radius: 4px 0 4px 0;
}
.footer {
text-align: center;
padding: 30px 0;
margin-top: 70px;
border-top: 1px solid #e5e5e5;
background-color: #f5f5f5;
}
.footer p {
margin-bottom: 0;
}
</style>
</head>
<body>
<div class="container" ng-controller="controller">
<header class="page-header">
<h1>AngularJS DateParser <small>Demo</small></h1>
</header>
<p>The AngularJS library has a <a href="http://docs.angularjs.org/api/ng/filter/date" target="_blank" title="AngularJS date filter">date filter</a> that allows JavaScript Date objects to be displayed using a provided format. This is an awesome feature, and it's great that you can use it anywhere, including text input boxes. But the problem is that it only works one-way. There's currently no way to convert strings back into Date objects while using the same format initially used to display it. This parser was designed to overcome this problem.</p>
<h4>Basic</h4>
<p>This is a basic example demonstrating how the parser can convert manually entered date strings into JavaScript Date objects.</p>
<div class="bs-docs-example">
<p>
<div class="input-prepend">
<span class="add-on">Date and time</span>
<input type="text" ng-model="date" date-parser="dd.MM.yyyy HH:mm" />
</div>
</p>
<p>Selected date: {{date | date:'MMM d, y h:mm a'}}</p>
</div>
<h6>Code</h6>
<div>
<pre class="brush: html"><input type="text" ng-model="date" date-parser="dd.MM.yyyy HH:mm" /></pre>
</div>
<h4>Using Angular Date Formats</h4>
<p>The AngularJS date filter comes with several shortname formats that you can use. The DateParser can recognise these formats and will convert the date strings accordingly.</p>
<div class="bs-docs-example">
<p>
<div class="input-prepend">
<span class="add-on">medium</span>
<input type="text" ng-model="date" date-parser="medium" />
</div>
</p>
<p>
<div class="input-prepend">
<span class="add-on">short</span>
<input type="text" ng-model="date" date-parser="short" />
</div>
</p>
<p>
<div class="input-prepend">
<span class="add-on">fullDate</span>
<input type="text" ng-model="date" date-parser="fullDate" />
</div>
</p>
<p>
<div class="input-prepend">
<span class="add-on">longDate</span>
<input type="text" ng-model="date" date-parser="longDate" />
</div>
</p>
<p>
<div class="input-prepend">
<span class="add-on">mediumDate</span>
<input type="text" ng-model="date" date-parser="mediumDate" />
</div>
</p>
<p>
<div class="input-prepend">
<span class="add-on">shortDate</span>
<input type="text" ng-model="date" date-parser="shortDate" />
</div>
</p>
<p>
<div class="input-prepend">
<span class="add-on">mediumTime</span>
<input type="text" ng-model="date" date-parser="mediumTime" />
</div>
</p>
<p>
<div class="input-prepend">
<span class="add-on">shortTime</span>
<input type="text" ng-model="date" date-parser="shortTime" />
</div>
</p>
<p>Selected date: {{date | date:'MMM d, y h:mm a'}}</p>
</div>
<h6>Code</h6>
<div>
<pre class="brush: html"><input type="text" ng-model="date" date-parser="medium" />
<input type="text" ng-model="date" date-parser="short" />
<input type="text" ng-model="date" date-parser="fullDate" />
<input type="text" ng-model="date" date-parser="longDate" />
<input type="text" ng-model="date" date-parser="mediumDate" />
<input type="text" ng-model="date" date-parser="shortDate" />
<input type="text" ng-model="date" date-parser="mediumTime" />
<input type="text" ng-model="date" date-parser="shortTime" />
</pre>
</div>
<h4>Dynamic Formats</h4>
<p>Date string formats can be changed on-the-fly and associated views will automatically be updated to use the new format.</p>
<div class="bs-docs-example">
<div class="input-prepend">
<span class="add-on">Format</span>
<input type="text" ng-model="format" />
</div>
<div class="input-prepend">
<span class="add-on">Date</span>
<input type="text" ng-model="date" date-parser="{{format}}" />
</div>
<p>Selected date: {{date | date:'MMM d, y h:mm a'}}</p>
</div>
<h6>Code</h6>
<div ng-non-bindable>
<pre class="brush: html" ng-><input type="text" ng-model="date" date-parser="{{format}}" /></pre>
</div>
<h4>Timezones</h4>
<p>The parser also allows you to change the timezone. However, bear in mind that the model will still contain the date and time for the local timezone, minus the offset.</p>
<div class="bs-docs-example">
<div class="input-prepend">
<span class="add-on">Date</span>
<input type="text" ng-model="date" date-parser="dd/MM/yyyy HH:mm Z" />
</div>
<p>Selected date: {{date | date:'MMM d, y h:mm a Z'}}</p>
</div>
<h6>Code</h6>
<div ng-non-bindable>
<pre class="brush: html" ng-><input type="text" ng-model="date" date-parser="dd/MM/yyyy HH:mm Z" /></pre>
</div>
</div>
<footer class="footer">
<div class="container">
<p>Copyright © 2014 <a href="http://dnasir.com" title="Dzulqarnain Nasir">Dzulqarnain Nasir</a></p>
<p>Code licensed under <a href="http://opensource.org/licenses/MIT" target="_blank" title="The MIT License">MIT License</a></p>
</div>
</footer>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.min.js"></script>
<script src="dist/angular-dateparser.min.js"></script>
<script>
function controller($scope) {
$scope.format = 'dd.MM.yyyy';
$scope.date = new Date();
}
</script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/SyntaxHighlighter/3.0.83/scripts/shCore.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/SyntaxHighlighter/3.0.83/scripts/shBrushXml.js"></script>
<script type="text/javascript">
SyntaxHighlighter.all();
</script>
</body>
</html>