Changes

JavaScript Date Object

910 bytes added, 16:50, 8 May 2007
Setting Specific Properties of a Date Object Instance
<td>setSeconds()<td>Sets the seconds property of the Date object<td>myDate.setSeconds(59)</td>
</table>
 
== Reading the Date and Time from a JavaScript Date Object ==
 
Just as with setting the properties of a JavaScript Date Object, there are a number of ways to read the date and time properties of the Date. One, less useful, way is to use the ''getTime()'' method of the Date object. The getTime() object returns the date and time of the user's system represented by the number of milliseconds since 00:00:00 on January 1, 1970. For example:
 
<pre>
var today = myDate.getTime()
</pre>
 
would return a value similar to 1182356520000 which doesn't mean an awful lot to a human being. Another methods is to read each of the individual Date properties using the getDate(), getMonth(), getFullYear(), getHours(), getMinutes(), getSeconds() methods:
 
<pre>
 
var myDate = new Date ("June 20, 2007 12:00:00");
 
document.write (getDate() + getMonth() + getFullYear() + getHours() + getMinutes() + getSeconds());
 
</pre>