The sections above have described all of the fundamental data types supported by JavaScript. Dates and times are not one of these fundamental types. But JavaScript does provide a type (or class) of object that represents dates and times, and can be used to manipulate this type of data. A Date object in JavaScript is created with the new operator and the Date() constructor:
now =index.html new Date(); // create an object representing the current date and time xmas =index.html new Date(96, 11, 25); // Create a Date object representing Christmas
Methods of the Date object allow you to get and set the various date and time values, and to convert the Date to a string, using either local time or GMT time. For example:
xmas.setYear(xmas.getYear() + 1); // Change the date to next Christmas document.write("Today is: " + now.toLocaleString());
You can find full documentation on the Date object and its methods in the reference section of this book. Unfortunately, the Date object is plagued with various bugs in Navigator 2.0. Appendix B, Known Bugs, contains details.
file: /Techref/language/java/script/definitive/ch03_10.htm, 4KB, , updated: 2019/10/14 16:00, local time: 2024/8/22 18:19,
52.14.24.45:LOG IN
|
©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://piclist.com/tecHREF/language/java/script/definitive/ch03_10.htm"> [Chapter 3] 3.10 The Date Object</A> |
Did you find what you needed? |
![]() o List host: MIT, Site host massmind.org, Top posters @none found - Page Editors: James Newton, David Cary, and YOU! * Roman Black of Black Robotics donates from sales of Linistep stepper controller kits. * Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters. * Monthly Subscribers: Gregg Rew. on-going support is MOST appreciated! * Contributors: Richard Seriani, Sr. |
Ashley Roll has put together a really nice little unit here. Leave off the MAX232 and keep these handy for the few times you need true RS232! |
.