JavaScript Objects: Dates
(Page 1 of 5 )
In the last tutorial we discussed the last of the String Objects. We left off with two to go, but one of those two doesn't work in IE (and therefore is not worth mentioning; VIVE BILL GATES!) and the other is code that JavaScript creates automatically for you. So I guess what I am saying here is I am not going to discuss those. I will however discuss my good buddy, the Date Object.The Date Object is made up of both Properties and Methods. Before we look at the Methods, let's go over the Properties.
Property | What it Does |
Constructor | Returns the function that created it |
Prototype | Used to add properties and methods to an object |
Constructor
The Date Constructor Property works similar to the Constructor in the String Object. It returns the function that created it. Here it is in code:
<html>
<body>
<script type="text/javascript">
var when=new Date()
if (when.constructor==Array)
{document.write("This object is an Array object")}
if (when.constructor==Boolean)
{document.write("This object is a Boolean object")}
if (when.constructor==Date)
{document.write("This object is a Date object")}
if (when.constructor==String)
{document.write("This object is a String object")}
</script>
</body>
</html>
This will print out:
This object is a Date object
Next: The Prototype Property >>
More JavaScript Articles
More By James Payne