2 |
aperonnet |
1 |
<div class="body-wrap">
|
|
|
2 |
<div class="top-tools">
|
|
|
3 |
<a class="inner-link" href="#Date-props"><img src="../resources/images/default/s.gif" class="item-icon icon-prop">Properties</a>
|
|
|
4 |
<a class="inner-link" href="#Date-methods"><img src="../resources/images/default/s.gif" class="item-icon icon-method">Methods</a>
|
|
|
5 |
<a class="inner-link" href="#Date-events"><img src="../resources/images/default/s.gif" class="item-icon icon-event">Events</a>
|
|
|
6 |
<a class="bookmark" href="../docs/?class=Date"><img src="../resources/images/default/s.gif" class="item-icon icon-fav">Direct Link</a>
|
|
|
7 |
</div>
|
|
|
8 |
<h1>Class Date</h1>
|
|
|
9 |
<table cellspacing="0">
|
|
|
10 |
<tr><td class="label">Package:</td><td class="hd-info">Global</td></tr>
|
|
|
11 |
<tr><td class="label">Defined In:</td><td class="hd-info"><a href="../source/util/Date.js" target="_blank">Date.js</a></td></tr>
|
|
|
12 |
<tr><td class="label">Class:</td><td class="hd-info">Date</td></tr>
|
|
|
13 |
<tr><td class="label">Extends:</td><td class="hd-info">Object</td></tr>
|
|
|
14 |
</table>
|
|
|
15 |
<div class="description">
|
|
|
16 |
The date parsing and format syntax is a subset of
|
|
|
17 |
<a href="http://www.php.net/date">PHP's date() function</a>, and the formats that are
|
|
|
18 |
supported will provide results equivalent to their PHP versions.
|
|
|
19 |
The following is a list of all currently supported formats:
|
|
|
20 |
<pre>Format Description Example returned values
|
|
|
21 |
------ ----------------------------------------------------------------------- -----------------------
|
|
|
22 |
d Day of the month, 2 digits with leading zeros 01 to 31
|
|
|
23 |
D A short textual representation of the day of the week Mon to Sun
|
|
|
24 |
j Day of the month without leading zeros 1 to 31
|
|
|
25 |
l A full textual representation of the day of the week Sunday to Saturday
|
|
|
26 |
N ISO-8601 numeric representation of the day of the week 1 (for Monday) through 7 (for Sunday)
|
|
|
27 |
S English ordinal suffix for the day of the month, 2 characters st, nd, rd or th. Works well with j
|
|
|
28 |
w Numeric representation of the day of the week 0 (for Sunday) to 6 (for Saturday)
|
|
|
29 |
z The day of the year (starting from 0) 0 to 364 (365 in leap years)
|
|
|
30 |
W ISO-8601 week number of year, weeks starting on Monday 01 to 53
|
|
|
31 |
F A full textual representation of a month, such as January or March January to December
|
|
|
32 |
m Numeric representation of a month, with leading zeros 01 to 12
|
|
|
33 |
M A short textual representation of a month Jan to Dec
|
|
|
34 |
n Numeric representation of a month, without leading zeros 1 to 12
|
|
|
35 |
t Number of days in the given month 28 to 31
|
|
|
36 |
L Whether it's a leap year 1 if it is a leap year, 0 otherwise.
|
|
|
37 |
o ISO-8601 year number (identical to (Y), but if the ISO week number (W) Examples: 1998 or 2004
|
|
|
38 |
belongs to the previous or next year, that year is used instead)
|
|
|
39 |
Y A full numeric representation of a year, 4 digits Examples: 1999 or 2003
|
|
|
40 |
y A two digit representation of a year Examples: 99 or 03
|
|
|
41 |
a Lowercase Ante meridiem and Post meridiem am or pm
|
|
|
42 |
A Uppercase Ante meridiem and Post meridiem AM or PM
|
|
|
43 |
g 12-hour format of an hour without leading zeros 1 to 12
|
|
|
44 |
G 24-hour format of an hour without leading zeros 0 to 23
|
|
|
45 |
h 12-hour format of an hour with leading zeros 01 to 12
|
|
|
46 |
H 24-hour format of an hour with leading zeros 00 to 23
|
|
|
47 |
i Minutes, with leading zeros 00 to 59
|
|
|
48 |
s Seconds, with leading zeros 00 to 59
|
|
|
49 |
u Milliseconds, with leading zeros 001 to 999
|
|
|
50 |
O Difference to Greenwich time (GMT) in hours and minutes Example: +1030
|
|
|
51 |
P Difference to Greenwich time (GMT) with colon between hours and minutes Example: -08:00
|
|
|
52 |
T Timezone abbreviation of the machine running the code Examples: EST, MDT, PDT ...
|
|
|
53 |
Z Timezone offset in seconds (negative if west of UTC, positive if east) -43200 to 50400
|
|
|
54 |
c ISO 8601 date 2007-04-17T15:19:21+08:00
|
|
|
55 |
U Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT) 1193432466 or -2138434463</pre>
|
|
|
56 |
Example usage (note that you must escape format specifiers with '\\' to render them as character literals):
|
|
|
57 |
<pre><code><i>// Sample date:</i>
|
|
|
58 |
<i>// <em>'Wed Jan 10 2007 15:05:01 GMT-0600 (Central Standard Time)'</em></i>
|
|
|
59 |
|
|
|
60 |
<b>var</b> dt = <b>new</b> Date(<em>'1/10/2007 03:05:01 PM GMT-0600'</em>);
|
|
|
61 |
document.write(dt.format(<em>'Y-m-d'</em>)); <i>// 2007-01-10</i>
|
|
|
62 |
document.write(dt.format(<em>'F j, Y, g:i a'</em>)); <i>// January 10, 2007, 3:05 pm</i>
|
|
|
63 |
document.write(dt.format(<em>'l, \\t\\he jS of F Y h:i:s A'</em>)); // Wednesday, the 10th of January 2007 03:05:01 PM</code></pre>
|
|
|
64 |
Here are some standard date/time patterns that you might find helpful. They
|
|
|
65 |
are not part of the source of Date.js, but to use them you can simply copy this
|
|
|
66 |
block of code into any script that is included after Date.js and they will also become
|
|
|
67 |
globally available on the Date object. Feel free to add or remove patterns as needed in your code.
|
|
|
68 |
<pre><code>Date.patterns = {
|
|
|
69 |
ISO8601Long:<em>"Y-m-d H:i:s"</em>,
|
|
|
70 |
ISO8601Short:<em>"Y-m-d"</em>,
|
|
|
71 |
ShortDate: <em>"n/j/Y"</em>,
|
|
|
72 |
LongDate: <em>"l, F d, Y"</em>,
|
|
|
73 |
FullDateTime: <em>"l, F d, Y g:i:s A"</em>,
|
|
|
74 |
MonthDay: <em>"F d"</em>,
|
|
|
75 |
ShortTime: <em>"g:i A"</em>,
|
|
|
76 |
LongTime: <em>"g:i:s A"</em>,
|
|
|
77 |
SortableDateTime: <em>"Y-m-d\\TH:i:s"</em>,
|
|
|
78 |
UniversalSortableDateTime: <em>"Y-m-d H:i:sO"</em>,
|
|
|
79 |
YearMonth: <em>"F, Y"</em>
|
|
|
80 |
};</code></pre>
|
|
|
81 |
Example usage:
|
|
|
82 |
<pre><code>var dt = <b>new</b> Date();
|
|
|
83 |
document.write(dt.format(Date.patterns.ShortDate));</code></pre> </div>
|
|
|
84 |
|
|
|
85 |
<div class="hr"></div>
|
|
|
86 |
<a id="Date-props"></a>
|
|
|
87 |
<h2>Public Properties</h2>
|
|
|
88 |
<table cellspacing="0" class="member-table">
|
|
|
89 |
<tr>
|
|
|
90 |
<th class="sig-header" colspan="2">Property</th>
|
|
|
91 |
<th class="msource-header">Defined By</th>
|
|
|
92 |
</tr>
|
|
|
93 |
<tr class="property-row">
|
|
|
94 |
<td class="micon"><a class="exi" href="#expand"> </a></td>
|
|
|
95 |
<td class="sig">
|
|
|
96 |
<a id="Date-Date.DAY"></a>
|
|
|
97 |
<b>Date.DAY</b> : String <div class="mdesc">
|
|
|
98 |
<static> Date interval constant </div>
|
|
|
99 |
</td>
|
|
|
100 |
<td class="msource">Date</td>
|
|
|
101 |
</tr>
|
|
|
102 |
<tr class="property-row alt">
|
|
|
103 |
<td class="micon"><a class="exi" href="#expand"> </a></td>
|
|
|
104 |
<td class="sig">
|
|
|
105 |
<a id="Date-Date.HOUR"></a>
|
|
|
106 |
<b>Date.HOUR</b> : String <div class="mdesc">
|
|
|
107 |
<static> Date interval constant </div>
|
|
|
108 |
</td>
|
|
|
109 |
<td class="msource">Date</td>
|
|
|
110 |
</tr>
|
|
|
111 |
<tr class="property-row">
|
|
|
112 |
<td class="micon"><a class="exi" href="#expand"> </a></td>
|
|
|
113 |
<td class="sig">
|
|
|
114 |
<a id="Date-Date.MILLI"></a>
|
|
|
115 |
<b>Date.MILLI</b> : String <div class="mdesc">
|
|
|
116 |
<static> Date interval constant </div>
|
|
|
117 |
</td>
|
|
|
118 |
<td class="msource">Date</td>
|
|
|
119 |
</tr>
|
|
|
120 |
<tr class="property-row alt">
|
|
|
121 |
<td class="micon"><a class="exi" href="#expand"> </a></td>
|
|
|
122 |
<td class="sig">
|
|
|
123 |
<a id="Date-Date.MINUTE"></a>
|
|
|
124 |
<b>Date.MINUTE</b> : String <div class="mdesc">
|
|
|
125 |
<static> Date interval constant </div>
|
|
|
126 |
</td>
|
|
|
127 |
<td class="msource">Date</td>
|
|
|
128 |
</tr>
|
|
|
129 |
<tr class="property-row">
|
|
|
130 |
<td class="micon"><a class="exi" href="#expand"> </a></td>
|
|
|
131 |
<td class="sig">
|
|
|
132 |
<a id="Date-Date.MONTH"></a>
|
|
|
133 |
<b>Date.MONTH</b> : String <div class="mdesc">
|
|
|
134 |
<static> Date interval constant </div>
|
|
|
135 |
</td>
|
|
|
136 |
<td class="msource">Date</td>
|
|
|
137 |
</tr>
|
|
|
138 |
<tr class="property-row alt">
|
|
|
139 |
<td class="micon"><a class="exi" href="#expand"> </a></td>
|
|
|
140 |
<td class="sig">
|
|
|
141 |
<a id="Date-Date.SECOND"></a>
|
|
|
142 |
<b>Date.SECOND</b> : String <div class="mdesc">
|
|
|
143 |
<static> Date interval constant </div>
|
|
|
144 |
</td>
|
|
|
145 |
<td class="msource">Date</td>
|
|
|
146 |
</tr>
|
|
|
147 |
<tr class="property-row">
|
|
|
148 |
<td class="micon"><a class="exi" href="#expand"> </a></td>
|
|
|
149 |
<td class="sig">
|
|
|
150 |
<a id="Date-Date.YEAR"></a>
|
|
|
151 |
<b>Date.YEAR</b> : String <div class="mdesc">
|
|
|
152 |
<static> Date interval constant </div>
|
|
|
153 |
</td>
|
|
|
154 |
<td class="msource">Date</td>
|
|
|
155 |
</tr>
|
|
|
156 |
<tr class="property-row alt expandable">
|
|
|
157 |
<td class="micon"><a class="exi" href="#expand"> </a></td>
|
|
|
158 |
<td class="sig">
|
|
|
159 |
<a id="Date-Date.dayNames"></a>
|
|
|
160 |
<b>Date.dayNames</b> : Array <div class="mdesc">
|
|
|
161 |
<div class="short"><static> An array of textual day names.
|
|
|
162 |
Override these values for international dates, for example...
|
|
|
163 |
Date.dayN...</div>
|
|
|
164 |
<div class="long">
|
|
|
165 |
<static> An array of textual day names.
|
|
|
166 |
Override these values for international dates, for example...
|
|
|
167 |
Date.dayNames = ['SundayInYourLang', 'MondayInYourLang', ...]; </div>
|
|
|
168 |
</div>
|
|
|
169 |
</td>
|
|
|
170 |
<td class="msource">Date</td>
|
|
|
171 |
</tr>
|
|
|
172 |
<tr class="property-row expandable">
|
|
|
173 |
<td class="micon"><a class="exi" href="#expand"> </a></td>
|
|
|
174 |
<td class="sig">
|
|
|
175 |
<a id="Date-Date.monthNames"></a>
|
|
|
176 |
<b>Date.monthNames</b> : Array <div class="mdesc">
|
|
|
177 |
<div class="short"><static> An array of textual month names.
|
|
|
178 |
Override these values for international dates, for example...
|
|
|
179 |
Date.mo...</div>
|
|
|
180 |
<div class="long">
|
|
|
181 |
<static> An array of textual month names.
|
|
|
182 |
Override these values for international dates, for example...
|
|
|
183 |
Date.monthNames = ['JanInYourLang', 'FebInYourLang', ...]; </div>
|
|
|
184 |
</div>
|
|
|
185 |
</td>
|
|
|
186 |
<td class="msource">Date</td>
|
|
|
187 |
</tr>
|
|
|
188 |
<tr class="property-row alt expandable">
|
|
|
189 |
<td class="micon"><a class="exi" href="#expand"> </a></td>
|
|
|
190 |
<td class="sig">
|
|
|
191 |
<a id="Date-Date.monthNumbers"></a>
|
|
|
192 |
<b>Date.monthNumbers</b> : Object <div class="mdesc">
|
|
|
193 |
<div class="short"><static> An object hash of zero-based javascript month numbers (with short month names as keys. note: keys are ...</div>
|
|
|
194 |
<div class="long">
|
|
|
195 |
<static> An object hash of zero-based javascript month numbers (with short month names as keys. note: keys are case-sensitive).
|
|
|
196 |
Override these values for international dates, for example...
|
|
|
197 |
Date.monthNumbers = {'ShortJanNameInYourLang':0, 'ShortFebNameInYourLang':1, ...}; </div>
|
|
|
198 |
</div>
|
|
|
199 |
</td>
|
|
|
200 |
<td class="msource">Date</td>
|
|
|
201 |
</tr>
|
|
|
202 |
</table>
|
|
|
203 |
<a id="Date-methods"></a>
|
|
|
204 |
<h2>Public Methods</h2>
|
|
|
205 |
<table cellspacing="0" class="member-table">
|
|
|
206 |
<tr>
|
|
|
207 |
<th class="sig-header" colspan="2">Method</th>
|
|
|
208 |
<th class="msource-header">Defined By</th>
|
|
|
209 |
</tr>
|
|
|
210 |
<tr class="method-row expandable">
|
|
|
211 |
<td class="micon"><a class="exi" href="#expand"> </a></td>
|
|
|
212 |
<td class="sig">
|
|
|
213 |
<a id="Date-Date.getMonthNumber"></a>
|
|
|
214 |
<b>Date.getMonthNumber</b>( <code>String name</code> ) : Number <div class="mdesc">
|
|
|
215 |
<div class="short"><static> Get the zero-based javascript month number for the given short/full month name.
|
|
|
216 |
Override this function...</div>
|
|
|
217 |
<div class="long">
|
|
|
218 |
<static> Get the zero-based javascript month number for the given short/full month name.
|
|
|
219 |
Override this function for international dates. <div class="mdetail-params">
|
|
|
220 |
<strong>Parameters:</strong>
|
|
|
221 |
<ul><li><code>name</code> : String<div class="sub-desc">The short/full month name.</div></li> </ul>
|
|
|
222 |
<strong>Returns:</strong>
|
|
|
223 |
<ul>
|
|
|
224 |
<li><code>Number</code><div class="sub-desc">The zero-based javascript month number.</div></li>
|
|
|
225 |
</ul>
|
|
|
226 |
</div>
|
|
|
227 |
</div>
|
|
|
228 |
</div>
|
|
|
229 |
</td>
|
|
|
230 |
<td class="msource">Date</td>
|
|
|
231 |
</tr>
|
|
|
232 |
<tr class="method-row alt expandable">
|
|
|
233 |
<td class="micon"><a class="exi" href="#expand"> </a></td>
|
|
|
234 |
<td class="sig">
|
|
|
235 |
<a id="Date-Date.getShortDayName"></a>
|
|
|
236 |
<b>Date.getShortDayName</b>( <code>Number day</code> ) : String <div class="mdesc">
|
|
|
237 |
<div class="short"><static> Get the short day name for the given day number.
|
|
|
238 |
Override this function for international dates.</div>
|
|
|
239 |
<div class="long">
|
|
|
240 |
<static> Get the short day name for the given day number.
|
|
|
241 |
Override this function for international dates. <div class="mdetail-params">
|
|
|
242 |
<strong>Parameters:</strong>
|
|
|
243 |
<ul><li><code>day</code> : Number<div class="sub-desc">A zero-based javascript day number.</div></li> </ul>
|
|
|
244 |
<strong>Returns:</strong>
|
|
|
245 |
<ul>
|
|
|
246 |
<li><code>String</code><div class="sub-desc">The short day name.</div></li>
|
|
|
247 |
</ul>
|
|
|
248 |
</div>
|
|
|
249 |
</div>
|
|
|
250 |
</div>
|
|
|
251 |
</td>
|
|
|
252 |
<td class="msource">Date</td>
|
|
|
253 |
</tr>
|
|
|
254 |
<tr class="method-row expandable">
|
|
|
255 |
<td class="micon"><a class="exi" href="#expand"> </a></td>
|
|
|
256 |
<td class="sig">
|
|
|
257 |
<a id="Date-Date.getShortMonthName"></a>
|
|
|
258 |
<b>Date.getShortMonthName</b>( <code>Number month</code> ) : String <div class="mdesc">
|
|
|
259 |
<div class="short"><static> Get the short month name for the given month number.
|
|
|
260 |
Override this function for international dates.</div>
|
|
|
261 |
<div class="long">
|
|
|
262 |
<static> Get the short month name for the given month number.
|
|
|
263 |
Override this function for international dates. <div class="mdetail-params">
|
|
|
264 |
<strong>Parameters:</strong>
|
|
|
265 |
<ul><li><code>month</code> : Number<div class="sub-desc">A zero-based javascript month number.</div></li> </ul>
|
|
|
266 |
<strong>Returns:</strong>
|
|
|
267 |
<ul>
|
|
|
268 |
<li><code>String</code><div class="sub-desc">The short month name.</div></li>
|
|
|
269 |
</ul>
|
|
|
270 |
</div>
|
|
|
271 |
</div>
|
|
|
272 |
</div>
|
|
|
273 |
</td>
|
|
|
274 |
<td class="msource">Date</td>
|
|
|
275 |
</tr>
|
|
|
276 |
<tr class="method-row alt expandable">
|
|
|
277 |
<td class="micon"><a class="exi" href="#expand"> </a></td>
|
|
|
278 |
<td class="sig">
|
|
|
279 |
<a id="Date-Date.parseDate"></a>
|
|
|
280 |
<b>Date.parseDate</b>( <code>String input</code>, <code>String format</code> ) : Date <div class="mdesc">
|
|
|
281 |
<div class="short"><static> Parses the passed string using the specified format. Note that this function expects dates in normal c...</div>
|
|
|
282 |
<div class="long">
|
|
|
283 |
<static> Parses the passed string using the specified format. Note that this function expects dates in normal calendar
|
|
|
284 |
format, meaning that months are 1-based (1 = January) and not zero-based like in JavaScript dates. Any part of
|
|
|
285 |
the date format that is not specified will default to the current date value for that part. Time parts can also
|
|
|
286 |
be specified, but default to 0. Keep in mind that the input date string must precisely match the specified format
|
|
|
287 |
string or the parse operation will fail.
|
|
|
288 |
Example Usage:
|
|
|
289 |
<pre><code><i>//dt = Fri May 25 2007 (current date)</i>
|
|
|
290 |
<b>var</b> dt = <b>new</b> Date();
|
|
|
291 |
|
|
|
292 |
<i>//dt = Thu May 25 2006 (today's month/day <b>in</b> 2006)</i>
|
|
|
293 |
dt = Date.parseDate(<em>"2006"</em>, <em>"Y"</em>);
|
|
|
294 |
|
|
|
295 |
<i>//dt = Sun Jan 15 2006 (all date parts specified)</i>
|
|
|
296 |
dt = Date.parseDate(<em>"2006-01-15"</em>, <em>"Y-m-d"</em>);
|
|
|
297 |
|
|
|
298 |
<i>//dt = Sun Jan 15 2006 15:20:01 GMT-0600 (CST)</i>
|
|
|
299 |
dt = Date.parseDate(<em>"2006-01-15 3:20:01 PM"</em>, <em>"Y-m-d h:i:s A"</em> );</code></pre> <div class="mdetail-params">
|
|
|
300 |
<strong>Parameters:</strong>
|
|
|
301 |
<ul><li><code>input</code> : String<div class="sub-desc">The unparsed date as a string.</div></li><li><code>format</code> : String<div class="sub-desc">The format the date is in.</div></li> </ul>
|
|
|
302 |
<strong>Returns:</strong>
|
|
|
303 |
<ul>
|
|
|
304 |
<li><code>Date</code><div class="sub-desc">The parsed date.</div></li>
|
|
|
305 |
</ul>
|
|
|
306 |
</div>
|
|
|
307 |
</div>
|
|
|
308 |
</div>
|
|
|
309 |
</td>
|
|
|
310 |
<td class="msource">Date</td>
|
|
|
311 |
</tr>
|
|
|
312 |
<tr class="method-row expandable">
|
|
|
313 |
<td class="micon"><a class="exi" href="#expand"> </a></td>
|
|
|
314 |
<td class="sig">
|
|
|
315 |
<a id="Date-add"></a>
|
|
|
316 |
<b>add</b>( <code>String interval</code>, <code>Number value</code> ) : Date <div class="mdesc">
|
|
|
317 |
<div class="short">Provides a convenient method of performing basic date arithmetic. This method
|
|
|
318 |
does not modify the Date instance bein...</div>
|
|
|
319 |
<div class="long">
|
|
|
320 |
Provides a convenient method of performing basic date arithmetic. This method
|
|
|
321 |
does not modify the Date instance being called - it creates and returns
|
|
|
322 |
a new Date instance containing the resulting date value.
|
|
|
323 |
Examples:
|
|
|
324 |
<pre><code><i>//Basic usage:</i>
|
|
|
325 |
<b>var</b> dt = <b>new</b> Date(<em>'10/29/2006'</em>).add(Date.DAY, 5);
|
|
|
326 |
document.write(dt); <i>//returns <em>'Fri Oct 06 2006 00:00:00'</em></i>
|
|
|
327 |
|
|
|
328 |
<i>//Negative values will subtract correctly:</i>
|
|
|
329 |
<b>var</b> dt2 = <b>new</b> Date(<em>'10/1/2006'</em>).add(Date.DAY, -5);
|
|
|
330 |
document.write(dt2); <i>//returns <em>'Tue Sep 26 2006 00:00:00'</em></i>
|
|
|
331 |
|
|
|
332 |
<i>//You can even chain several calls together <b>in</b> one line!</i>
|
|
|
333 |
<b>var</b> dt3 = <b>new</b> Date(<em>'10/1/2006'</em>).add(Date.DAY, 5).add(Date.HOUR, 8).add(Date.MINUTE, -30);
|
|
|
334 |
document.write(dt3); //returns <em>'Fri Oct 06 2006 07:30:00'</em></code></pre> <div class="mdetail-params">
|
|
|
335 |
<strong>Parameters:</strong>
|
|
|
336 |
<ul><li><code>interval</code> : String<div class="sub-desc">A valid date interval enum value.</div></li><li><code>value</code> : Number<div class="sub-desc">The amount to add to the current date.</div></li> </ul>
|
|
|
337 |
<strong>Returns:</strong>
|
|
|
338 |
<ul>
|
|
|
339 |
<li><code>Date</code><div class="sub-desc">The new Date instance.</div></li>
|
|
|
340 |
</ul>
|
|
|
341 |
</div>
|
|
|
342 |
</div>
|
|
|
343 |
</div>
|
|
|
344 |
</td>
|
|
|
345 |
<td class="msource">Date</td>
|
|
|
346 |
</tr>
|
|
|
347 |
<tr class="method-row alt expandable">
|
|
|
348 |
<td class="micon"><a class="exi" href="#expand"> </a></td>
|
|
|
349 |
<td class="sig">
|
|
|
350 |
<a id="Date-between"></a>
|
|
|
351 |
<b>between</b>( <code>Date start</code>, <code>Date end</code> ) : Boolean <div class="mdesc">
|
|
|
352 |
<div class="short">Checks if this date falls on or between the given start and end dates.</div>
|
|
|
353 |
<div class="long">
|
|
|
354 |
Checks if this date falls on or between the given start and end dates. <div class="mdetail-params">
|
|
|
355 |
<strong>Parameters:</strong>
|
|
|
356 |
<ul><li><code>start</code> : Date<div class="sub-desc">Start date</div></li><li><code>end</code> : Date<div class="sub-desc">End date</div></li> </ul>
|
|
|
357 |
<strong>Returns:</strong>
|
|
|
358 |
<ul>
|
|
|
359 |
<li><code>Boolean</code><div class="sub-desc">true if this date falls on or between the given start and end dates.</div></li>
|
|
|
360 |
</ul>
|
|
|
361 |
</div>
|
|
|
362 |
</div>
|
|
|
363 |
</div>
|
|
|
364 |
</td>
|
|
|
365 |
<td class="msource">Date</td>
|
|
|
366 |
</tr>
|
|
|
367 |
<tr class="method-row expandable">
|
|
|
368 |
<td class="micon"><a class="exi" href="#expand"> </a></td>
|
|
|
369 |
<td class="sig">
|
|
|
370 |
<a id="Date-clearTime"></a>
|
|
|
371 |
<b>clearTime</b>( <code>Boolean clone</code> ) : Date <div class="mdesc">
|
|
|
372 |
<div class="short">Clears any time information from this date.</div>
|
|
|
373 |
<div class="long">
|
|
|
374 |
Clears any time information from this date. <div class="mdetail-params">
|
|
|
375 |
<strong>Parameters:</strong>
|
|
|
376 |
<ul><li><code>clone</code> : Boolean<div class="sub-desc">true to create a clone of this date, clear the time and return it (defaults to false).</div></li> </ul>
|
|
|
377 |
<strong>Returns:</strong>
|
|
|
378 |
<ul>
|
|
|
379 |
<li><code>Date</code><div class="sub-desc">this or the clone.</div></li>
|
|
|
380 |
</ul>
|
|
|
381 |
</div>
|
|
|
382 |
</div>
|
|
|
383 |
</div>
|
|
|
384 |
</td>
|
|
|
385 |
<td class="msource">Date</td>
|
|
|
386 |
</tr>
|
|
|
387 |
<tr class="method-row alt expandable">
|
|
|
388 |
<td class="micon"><a class="exi" href="#expand"> </a></td>
|
|
|
389 |
<td class="sig">
|
|
|
390 |
<a id="Date-clone"></a>
|
|
|
391 |
<b>clone</b>() : Date <div class="mdesc">
|
|
|
392 |
<div class="short">Creates and returns a new Date instance with the exact same date value as the called instance.
|
|
|
393 |
Dates are copied and p...</div>
|
|
|
394 |
<div class="long">
|
|
|
395 |
Creates and returns a new Date instance with the exact same date value as the called instance.
|
|
|
396 |
Dates are copied and passed by reference, so if a copied date variable is modified later, the original
|
|
|
397 |
variable will also be changed. When the intention is to create a new variable that will not
|
|
|
398 |
modify the original instance, you should create a clone.
|
|
|
399 |
Example of correctly cloning a date:
|
|
|
400 |
<pre><code><i>//wrong way:</i>
|
|
|
401 |
<b>var</b> orig = <b>new</b> Date(<em>'10/1/2006'</em>);
|
|
|
402 |
<b>var</b> copy = orig;
|
|
|
403 |
copy.setDate(5);
|
|
|
404 |
document.write(orig); <i>//returns <em>'Thu Oct 05 2006'</em>!</i>
|
|
|
405 |
|
|
|
406 |
<i>//correct way:</i>
|
|
|
407 |
<b>var</b> orig = <b>new</b> Date(<em>'10/1/2006'</em>);
|
|
|
408 |
<b>var</b> copy = orig.clone();
|
|
|
409 |
copy.setDate(5);
|
|
|
410 |
document.write(orig); //returns <em>'Thu Oct 01 2006'</em></code></pre> <div class="mdetail-params">
|
|
|
411 |
<strong>Parameters:</strong>
|
|
|
412 |
<ul><li>None.</li> </ul>
|
|
|
413 |
<strong>Returns:</strong>
|
|
|
414 |
<ul>
|
|
|
415 |
<li><code>Date</code><div class="sub-desc">The new Date instance.</div></li>
|
|
|
416 |
</ul>
|
|
|
417 |
</div>
|
|
|
418 |
</div>
|
|
|
419 |
</div>
|
|
|
420 |
</td>
|
|
|
421 |
<td class="msource">Date</td>
|
|
|
422 |
</tr>
|
|
|
423 |
<tr class="method-row expandable">
|
|
|
424 |
<td class="micon"><a class="exi" href="#expand"> </a></td>
|
|
|
425 |
<td class="sig">
|
|
|
426 |
<a id="Date-format"></a>
|
|
|
427 |
<b>format</b>( <code>String format</code> ) : String <div class="mdesc">
|
|
|
428 |
<div class="short">Formats a date given the supplied format string.</div>
|
|
|
429 |
<div class="long">
|
|
|
430 |
Formats a date given the supplied format string. <div class="mdetail-params">
|
|
|
431 |
<strong>Parameters:</strong>
|
|
|
432 |
<ul><li><code>format</code> : String<div class="sub-desc">The format string.</div></li> </ul>
|
|
|
433 |
<strong>Returns:</strong>
|
|
|
434 |
<ul>
|
|
|
435 |
<li><code>String</code><div class="sub-desc">The formatted date.</div></li>
|
|
|
436 |
</ul>
|
|
|
437 |
</div>
|
|
|
438 |
</div>
|
|
|
439 |
</div>
|
|
|
440 |
</td>
|
|
|
441 |
<td class="msource">Date</td>
|
|
|
442 |
</tr>
|
|
|
443 |
<tr class="method-row alt expandable">
|
|
|
444 |
<td class="micon"><a class="exi" href="#expand"> </a></td>
|
|
|
445 |
<td class="sig">
|
|
|
446 |
<a id="Date-getDayOfYear"></a>
|
|
|
447 |
<b>getDayOfYear</b>() : Number <div class="mdesc">
|
|
|
448 |
<div class="short">Get the numeric day number of the year, adjusted for leap year.</div>
|
|
|
449 |
<div class="long">
|
|
|
450 |
Get the numeric day number of the year, adjusted for leap year. <div class="mdetail-params">
|
|
|
451 |
<strong>Parameters:</strong>
|
|
|
452 |
<ul><li>None.</li> </ul>
|
|
|
453 |
<strong>Returns:</strong>
|
|
|
454 |
<ul>
|
|
|
455 |
<li><code>Number</code><div class="sub-desc">0 to 364 (365 in leap years).</div></li>
|
|
|
456 |
</ul>
|
|
|
457 |
</div>
|
|
|
458 |
</div>
|
|
|
459 |
</div>
|
|
|
460 |
</td>
|
|
|
461 |
<td class="msource">Date</td>
|
|
|
462 |
</tr>
|
|
|
463 |
<tr class="method-row expandable">
|
|
|
464 |
<td class="micon"><a class="exi" href="#expand"> </a></td>
|
|
|
465 |
<td class="sig">
|
|
|
466 |
<a id="Date-getDaysInMonth"></a>
|
|
|
467 |
<b>getDaysInMonth</b>() : Number <div class="mdesc">
|
|
|
468 |
<div class="short">Get the number of days in the current month, adjusted for leap year.</div>
|
|
|
469 |
<div class="long">
|
|
|
470 |
Get the number of days in the current month, adjusted for leap year. <div class="mdetail-params">
|
|
|
471 |
<strong>Parameters:</strong>
|
|
|
472 |
<ul><li>None.</li> </ul>
|
|
|
473 |
<strong>Returns:</strong>
|
|
|
474 |
<ul>
|
|
|
475 |
<li><code>Number</code><div class="sub-desc">The number of days in the month.</div></li>
|
|
|
476 |
</ul>
|
|
|
477 |
</div>
|
|
|
478 |
</div>
|
|
|
479 |
</div>
|
|
|
480 |
</td>
|
|
|
481 |
<td class="msource">Date</td>
|
|
|
482 |
</tr>
|
|
|
483 |
<tr class="method-row alt expandable">
|
|
|
484 |
<td class="micon"><a class="exi" href="#expand"> </a></td>
|
|
|
485 |
<td class="sig">
|
|
|
486 |
<a id="Date-getElapsed"></a>
|
|
|
487 |
<b>getElapsed</b>( <span class="optional" title="Optional">[<code>Date date</code>]</span> ) : Number <div class="mdesc">
|
|
|
488 |
<div class="short">Returns the number of milliseconds between this date and date</div>
|
|
|
489 |
<div class="long">
|
|
|
490 |
Returns the number of milliseconds between this date and date <div class="mdetail-params">
|
|
|
491 |
<strong>Parameters:</strong>
|
|
|
492 |
<ul><li><code>date</code> : Date<div class="sub-desc">(optional) Defaults to now</div></li> </ul>
|
|
|
493 |
<strong>Returns:</strong>
|
|
|
494 |
<ul>
|
|
|
495 |
<li><code>Number</code><div class="sub-desc">The diff in milliseconds</div></li>
|
|
|
496 |
</ul>
|
|
|
497 |
</div>
|
|
|
498 |
</div>
|
|
|
499 |
</div>
|
|
|
500 |
</td>
|
|
|
501 |
<td class="msource">Date</td>
|
|
|
502 |
</tr>
|
|
|
503 |
<tr class="method-row expandable">
|
|
|
504 |
<td class="micon"><a class="exi" href="#expand"> </a></td>
|
|
|
505 |
<td class="sig">
|
|
|
506 |
<a id="Date-getFirstDateOfMonth"></a>
|
|
|
507 |
<b>getFirstDateOfMonth</b>() : Date <div class="mdesc">
|
|
|
508 |
<div class="short">Get the date of the first day of the month in which this date resides.</div>
|
|
|
509 |
<div class="long">
|
|
|
510 |
Get the date of the first day of the month in which this date resides. <div class="mdetail-params">
|
|
|
511 |
<strong>Parameters:</strong>
|
|
|
512 |
<ul><li>None.</li> </ul>
|
|
|
513 |
<strong>Returns:</strong>
|
|
|
514 |
<ul>
|
|
|
515 |
<li><code>Date</code></li>
|
|
|
516 |
</ul>
|
|
|
517 |
</div>
|
|
|
518 |
</div>
|
|
|
519 |
</div>
|
|
|
520 |
</td>
|
|
|
521 |
<td class="msource">Date</td>
|
|
|
522 |
</tr>
|
|
|
523 |
<tr class="method-row alt expandable">
|
|
|
524 |
<td class="micon"><a class="exi" href="#expand"> </a></td>
|
|
|
525 |
<td class="sig">
|
|
|
526 |
<a id="Date-getFirstDayOfMonth"></a>
|
|
|
527 |
<b>getFirstDayOfMonth</b>() : Number <div class="mdesc">
|
|
|
528 |
<div class="short">Get the first day of the current month, adjusted for leap year. The returned value
|
|
|
529 |
is the numeric day index within t...</div>
|
|
|
530 |
<div class="long">
|
|
|
531 |
Get the first day of the current month, adjusted for leap year. The returned value
|
|
|
532 |
is the numeric day index within the week (0-6) which can be used in conjunction with
|
|
|
533 |
the <a ext:cls="Date" ext:member="monthNames" href="output/Date.html#monthNames">monthNames</a> array to retrieve the textual day name.
|
|
|
534 |
Example:
|
|
|
535 |
<pre><code>var dt = <b>new</b> Date(<em>'1/10/2007'</em>);
|
|
|
536 |
document.write(Date.dayNames[dt.getFirstDayOfMonth()]); //output: <em>'Monday'</em></code></pre> <div class="mdetail-params">
|
|
|
537 |
<strong>Parameters:</strong>
|
|
|
538 |
<ul><li>None.</li> </ul>
|
|
|
539 |
<strong>Returns:</strong>
|
|
|
540 |
<ul>
|
|
|
541 |
<li><code>Number</code><div class="sub-desc">The day number (0-6).</div></li>
|
|
|
542 |
</ul>
|
|
|
543 |
</div>
|
|
|
544 |
</div>
|
|
|
545 |
</div>
|
|
|
546 |
</td>
|
|
|
547 |
<td class="msource">Date</td>
|
|
|
548 |
</tr>
|
|
|
549 |
<tr class="method-row expandable">
|
|
|
550 |
<td class="micon"><a class="exi" href="#expand"> </a></td>
|
|
|
551 |
<td class="sig">
|
|
|
552 |
<a id="Date-getGMTOffset"></a>
|
|
|
553 |
<b>getGMTOffset</b>( <code>Boolean colon</code> ) : String <div class="mdesc">
|
|
|
554 |
<div class="short">Get the offset from GMT of the current date (equivalent to the format specifier 'O').</div>
|
|
|
555 |
<div class="long">
|
|
|
556 |
Get the offset from GMT of the current date (equivalent to the format specifier 'O'). <div class="mdetail-params">
|
|
|
557 |
<strong>Parameters:</strong>
|
|
|
558 |
<ul><li><code>colon</code> : Boolean<div class="sub-desc">true to separate the hours and minutes with a colon (defaults to false).</div></li> </ul>
|
|
|
559 |
<strong>Returns:</strong>
|
|
|
560 |
<ul>
|
|
|
561 |
<li><code>String</code><div class="sub-desc">The 4-character offset string prefixed with + or - (e.g. '-0600').</div></li>
|
|
|
562 |
</ul>
|
|
|
563 |
</div>
|
|
|
564 |
</div>
|
|
|
565 |
</div>
|
|
|
566 |
</td>
|
|
|
567 |
<td class="msource">Date</td>
|
|
|
568 |
</tr>
|
|
|
569 |
<tr class="method-row alt expandable">
|
|
|
570 |
<td class="micon"><a class="exi" href="#expand"> </a></td>
|
|
|
571 |
<td class="sig">
|
|
|
572 |
<a id="Date-getLastDateOfMonth"></a>
|
|
|
573 |
<b>getLastDateOfMonth</b>() : Date <div class="mdesc">
|
|
|
574 |
<div class="short">Get the date of the last day of the month in which this date resides.</div>
|
|
|
575 |
<div class="long">
|
|
|
576 |
Get the date of the last day of the month in which this date resides. <div class="mdetail-params">
|
|
|
577 |
<strong>Parameters:</strong>
|
|
|
578 |
<ul><li>None.</li> </ul>
|
|
|
579 |
<strong>Returns:</strong>
|
|
|
580 |
<ul>
|
|
|
581 |
<li><code>Date</code></li>
|
|
|
582 |
</ul>
|
|
|
583 |
</div>
|
|
|
584 |
</div>
|
|
|
585 |
</div>
|
|
|
586 |
</td>
|
|
|
587 |
<td class="msource">Date</td>
|
|
|
588 |
</tr>
|
|
|
589 |
<tr class="method-row expandable">
|
|
|
590 |
<td class="micon"><a class="exi" href="#expand"> </a></td>
|
|
|
591 |
<td class="sig">
|
|
|
592 |
<a id="Date-getLastDayOfMonth"></a>
|
|
|
593 |
<b>getLastDayOfMonth</b>() : Number <div class="mdesc">
|
|
|
594 |
<div class="short">Get the last day of the current month, adjusted for leap year. The returned value
|
|
|
595 |
is the numeric day index within th...</div>
|
|
|
596 |
<div class="long">
|
|
|
597 |
Get the last day of the current month, adjusted for leap year. The returned value
|
|
|
598 |
is the numeric day index within the week (0-6) which can be used in conjunction with
|
|
|
599 |
the <a ext:cls="Date" ext:member="monthNames" href="output/Date.html#monthNames">monthNames</a> array to retrieve the textual day name.
|
|
|
600 |
Example:
|
|
|
601 |
<pre><code>var dt = <b>new</b> Date(<em>'1/10/2007'</em>);
|
|
|
602 |
document.write(Date.dayNames[dt.getLastDayOfMonth()]); //output: <em>'Wednesday'</em></code></pre> <div class="mdetail-params">
|
|
|
603 |
<strong>Parameters:</strong>
|
|
|
604 |
<ul><li>None.</li> </ul>
|
|
|
605 |
<strong>Returns:</strong>
|
|
|
606 |
<ul>
|
|
|
607 |
<li><code>Number</code><div class="sub-desc">The day number (0-6).</div></li>
|
|
|
608 |
</ul>
|
|
|
609 |
</div>
|
|
|
610 |
</div>
|
|
|
611 |
</div>
|
|
|
612 |
</td>
|
|
|
613 |
<td class="msource">Date</td>
|
|
|
614 |
</tr>
|
|
|
615 |
<tr class="method-row alt expandable">
|
|
|
616 |
<td class="micon"><a class="exi" href="#expand"> </a></td>
|
|
|
617 |
<td class="sig">
|
|
|
618 |
<a id="Date-getSuffix"></a>
|
|
|
619 |
<b>getSuffix</b>() : String <div class="mdesc">
|
|
|
620 |
<div class="short">Get the English ordinal suffix of the current day (equivalent to the format specifier 'S').</div>
|
|
|
621 |
<div class="long">
|
|
|
622 |
Get the English ordinal suffix of the current day (equivalent to the format specifier 'S'). <div class="mdetail-params">
|
|
|
623 |
<strong>Parameters:</strong>
|
|
|
624 |
<ul><li>None.</li> </ul>
|
|
|
625 |
<strong>Returns:</strong>
|
|
|
626 |
<ul>
|
|
|
627 |
<li><code>String</code><div class="sub-desc">'st, 'nd', 'rd' or 'th'.</div></li>
|
|
|
628 |
</ul>
|
|
|
629 |
</div>
|
|
|
630 |
</div>
|
|
|
631 |
</div>
|
|
|
632 |
</td>
|
|
|
633 |
<td class="msource">Date</td>
|
|
|
634 |
</tr>
|
|
|
635 |
<tr class="method-row expandable">
|
|
|
636 |
<td class="micon"><a class="exi" href="#expand"> </a></td>
|
|
|
637 |
<td class="sig">
|
|
|
638 |
<a id="Date-getTimezone"></a>
|
|
|
639 |
<b>getTimezone</b>() : String <div class="mdesc">
|
|
|
640 |
<div class="short">Get the timezone abbreviation of the current date (equivalent to the format specifier 'T').
|
|
|
641 |
Note: The date string ret...</div>
|
|
|
642 |
<div class="long">
|
|
|
643 |
Get the timezone abbreviation of the current date (equivalent to the format specifier 'T').
|
|
|
644 |
Note: The date string returned by the javascript Date object's toString() method varies
|
|
|
645 |
between browsers (e.g. FF vs IE) and system region settings (e.g. IE in Asia vs IE in America).
|
|
|
646 |
For a given date string e.g. "Thu Oct 25 2007 22:55:35 GMT+0800 (Malay Peninsula Standard Time)",
|
|
|
647 |
getTimezone() first tries to get the timezone abbreviation from between a pair of parentheses
|
|
|
648 |
(which may or may not be present), failing which it proceeds to get the timezone abbreviation
|
|
|
649 |
from the GMT offset portion of the date string. <div class="mdetail-params">
|
|
|
650 |
<strong>Parameters:</strong>
|
|
|
651 |
<ul><li>None.</li> </ul>
|
|
|
652 |
<strong>Returns:</strong>
|
|
|
653 |
<ul>
|
|
|
654 |
<li><code>String</code><div class="sub-desc">The abbreviated timezone name (e.g. 'CST', 'PDT', 'EDT', 'MPST' ...).</div></li>
|
|
|
655 |
</ul>
|
|
|
656 |
</div>
|
|
|
657 |
</div>
|
|
|
658 |
</div>
|
|
|
659 |
</td>
|
|
|
660 |
<td class="msource">Date</td>
|
|
|
661 |
</tr>
|
|
|
662 |
<tr class="method-row alt expandable">
|
|
|
663 |
<td class="micon"><a class="exi" href="#expand"> </a></td>
|
|
|
664 |
<td class="sig">
|
|
|
665 |
<a id="Date-getWeekOfYear"></a>
|
|
|
666 |
<b>getWeekOfYear</b>() : Number <div class="mdesc">
|
|
|
667 |
<div class="short">Get the numeric ISO-8601 week number of the year.
|
|
|
668 |
(equivalent to the format specifier 'W', but without a leading zero).</div>
|
|
|
669 |
<div class="long">
|
|
|
670 |
Get the numeric ISO-8601 week number of the year.
|
|
|
671 |
(equivalent to the format specifier 'W', but without a leading zero). <div class="mdetail-params">
|
|
|
672 |
<strong>Parameters:</strong>
|
|
|
673 |
<ul><li>None.</li> </ul>
|
|
|
674 |
<strong>Returns:</strong>
|
|
|
675 |
<ul>
|
|
|
676 |
<li><code>Number</code><div class="sub-desc">1 to 53</div></li>
|
|
|
677 |
</ul>
|
|
|
678 |
</div>
|
|
|
679 |
</div>
|
|
|
680 |
</div>
|
|
|
681 |
</td>
|
|
|
682 |
<td class="msource">Date</td>
|
|
|
683 |
</tr>
|
|
|
684 |
<tr class="method-row expandable">
|
|
|
685 |
<td class="micon"><a class="exi" href="#expand"> </a></td>
|
|
|
686 |
<td class="sig">
|
|
|
687 |
<a id="Date-isLeapYear"></a>
|
|
|
688 |
<b>isLeapYear</b>() : Boolean <div class="mdesc">
|
|
|
689 |
<div class="short">Whether or not the current date is in a leap year.</div>
|
|
|
690 |
<div class="long">
|
|
|
691 |
Whether or not the current date is in a leap year. <div class="mdetail-params">
|
|
|
692 |
<strong>Parameters:</strong>
|
|
|
693 |
<ul><li>None.</li> </ul>
|
|
|
694 |
<strong>Returns:</strong>
|
|
|
695 |
<ul>
|
|
|
696 |
<li><code>Boolean</code><div class="sub-desc">True if the current date is in a leap year, else false.</div></li>
|
|
|
697 |
</ul>
|
|
|
698 |
</div>
|
|
|
699 |
</div>
|
|
|
700 |
</div>
|
|
|
701 |
</td>
|
|
|
702 |
<td class="msource">Date</td>
|
|
|
703 |
</tr>
|
|
|
704 |
</table>
|
|
|
705 |
<a id="Date-events"></a>
|
|
|
706 |
<h2>Public Events</h2>
|
|
|
707 |
<div class="no-members">This class has no public events.</div>
|
|
|
708 |
</div>
|