<!-- JavaScript:Dates code snippet 3. -->
<!-- Create a 'Date' object and write the adjusted values to the page
in a recognised format by directly calling the Date object methods -->
<!-- Use of 'with statement' -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!-- Code source: http://www.justfigures.co.uk/ -->
<!-- A resource for web developers using XHTML, CSS, JavaScript, PHP -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>View code snippet page</title>
<script language="JavaScript" type="text/javascript">
<!-- begin
function writeDate()
{
/* create a new 'Date' object called 'now1' */
var now1 = new Date();
/* write out the values by using the dot notation with the Date object and methods */
document.write("Date is: "+now1.getDate()+"/"+(now1.getMonth()+1)+"/"+now1.getFullYear()+"<br />");
}
function writeWithDate()
{
var now2 = new Date();
/* use of 'with statement' to eliminate the need to name an
object when applying the method to the object */
with (now2)
{
document.write("Date is: "+getDate()+"/"+(getMonth()+1)+"/"+getFullYear());
}
}
// end -->
</script>
</head>
<body>
<script language="JavaScript" type="text/javascript">
<!--
writeDate();
writeWithDate();
// -->
</script>
</body>
</html>