You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
log("3. the day:",dayOfYear+' of the year '+date.getFullYear());
199
+
log("4. on:",dayOfWeek);
200
+
log("5. one special day of:",monthName);
201
+
log("6. isoFormat:",isoFormat);
202
+
log("7. shortFormat:",shortFormat);
203
+
log("8. longFormat:",longFormat);
204
+
log("9. time12hour:",time12Hour);
205
+
log("10. timeWithTimezone:",timeWithTimezone);
206
+
};
207
+
208
+
formatBirthday(myBirthday);
209
+
/*
210
+
1. I was born on: August 8, 1983
211
+
2. at: 8:30:00 AM
212
+
3. the day: 220 of the year 1983
213
+
4. on: Monday
214
+
5. one special day of: August
215
+
6. isoFormat: 1983-08-08T12:30:00.000Z
216
+
7. shortFormat: 8/8/1983
217
+
8. longFormat: Monday, August 8, 1983
218
+
9. time12hour: 8:30:00 AM
219
+
10. timeWithTimezone: 8/8/1983, 8:30:00 GMT-4 */
220
+
221
+
222
+
223
+
//REFERENCE INFORMATION:
224
+
225
+
226
+
/* Date-Formatting Methods
227
+
There are several Date type methods used specifically to format the date as a string. They are
228
+
as follows:
229
+
➤➤ toDateString()—Displays the date’s day of the week, month, day of the month, and year in
230
+
an implementation-specific format.
231
+
➤➤ toTimeString()—Displays the date’s hours, minutes, seconds, and time zone in an imple-
232
+
mentation-specific format.
233
+
➤➤ toLocaleDateString()—Displays the date’s day of the week, month, day of the month, and
234
+
year in an implementation- and locale-specific format.
235
+
➤➤ toLocaleTimeString()—Displays the date’s hours, minutes, and seconds in an implementa-
236
+
tion-specific format.
237
+
➤➤ toUTCString()—Displays the complete UTC date in an implementation-specific format.
238
+
The output of these methods, as with toLocaleString() and toString(), varies widely from
239
+
browser to browser and therefore can’t be employed in a user interface for consistent display of a date.
240
+
241
+
NOTE There is also a method called toGMTString(), which is equivalent to toUTCString() and is provided for backwards compatibility. However, the specification recommends that new code use toUTCString() exclusively.
242
+
243
+
Date/Time Component Methods
244
+
The remaining methods of the Date type (listed in the following table) deal directly with getting and
245
+
setting specific parts of the date value. Note that references to a UTC date mean the date value when
246
+
interpreted without a time-zone offset (the date when converted to GMT).
247
+
METHOD DESCRIPTION
248
+
getTime() Returns the milliseconds representation of the date; same as
249
+
valueOf().
250
+
setTime(milliseconds) Sets the milliseconds representation of the date, thus changing the entire date.
251
+
getFullYear() Returns the four-digit year (2019 instead of just 19).
252
+
getUTCFullYear() Returns the four-digit year of the UTC date value.
253
+
setFullYear(year) Sets the year of the date. The year must be given with four digits (2019 instead of just 19).
254
+
setUTCFullYear(year) Sets the year of the UTC date. The year must be given with four digits (2019 instead of just 19).
255
+
getMonth() Returns the month of the date, where 0 represents January and 11 represents December.
256
+
getUTCMonth() Returns the month of the UTC date, where 0 represents January and 11 represents December.
257
+
setMonth(month) Sets the month of the date, which is any number 0 or greater. Numbers greater than 11 add years.
258
+
setUTCMonth(month) Sets the month of the UTC date, which is any number 0 or greater. Numbers greater than 11 add years.
259
+
getDate() Returns the day of the month (1 through 31) for the date.
260
+
getUTCDate() Returns the day of the month (1 through 31) for the UTC date.
261
+
setDate(date) Sets the day of the month for the date. If the date is greater
262
+
than the number of days in the month, the month value also
263
+
gets increased.
264
+
setUTCDate(date) Sets the day of the month for the UTC date. If the date is greater than the number of days in the month, the month value also gets increased.
265
+
getDay() Returns the date’s day of the week as a number (where 0 represents Sunday and 6 represents Saturday).
266
+
getUTCDay() Returns the UTC date’s day of the week as a number (where 0 represents Sunday and 6 represents Saturday).
267
+
getHours() Returns the date’s hours as a number between 0 and 23.
268
+
getUTCHours() Returns the UTC date’s hours as a number between 0 and 23.
269
+
setHours(hours) Sets the date’s hours. Setting the hours to a number greater than 23 also increments the day of the month.
270
+
setUTCHours(hours) Sets the UTC date’s hours. Setting the hours to a number greater than 23 also increments the day of the month.
271
+
getMinutes() Returns the date’s minutes as a number between 0 and 59.
272
+
getUTCMinutes() Returns the UTC date’s minutes as a number between 0 and 59.
273
+
setMinutes(minutes) Sets the date’s minutes. Setting the minutes to a number greater than 59 also increments the hour.
274
+
setUTCMinutes(minutes) Sets the UTC date’s minutes. Setting the minutes to a number greater than 59 also increments the hour.
275
+
getSeconds() Returns the date’s seconds as a number between 0 and 59.
276
+
getUTCSeconds() Returns the UTC date’s seconds as a number between 0 and 59.
277
+
setSeconds(seconds) Sets the date’s seconds. Setting the seconds to a number greater than 59 also increments the minutes.
278
+
setUTCSeconds(seconds) Sets the UTC date’s seconds. Setting the seconds to a number greater than 59 also increments the minutes.
279
+
getMilliseconds() Returns the date’s milliseconds.
280
+
getUTCMilliseconds() Returns the UTC date’s milliseconds.
281
+
setMilliseconds(milliseconds) Sets the date’s milliseconds.
282
+
setUTCMilliseconds(milliseconds) Sets the UTC date’s milliseconds.
283
+
getTimezoneOffset() Returns the number of minutes that the local time zone is offset from UTC. For example, Eastern Standard Time returns 300. This value changes when an area goes into Daylight Saving Time. */
0 commit comments