<!-- JavaScript:Cookies code snippet 1. -->
<!-- Creating a transient cookie to store a single value: the time. -->

<!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">
//<![CDATA[
/* function getCookie() to retrieve the contents of a cookie 
by its name is detailed in JavaScript: Cookies code snippet 4 
and is therefore NOT included here to help clarity */
//]]>
</script>
</head>

<body>
<script language="JavaScript" type="text/javascript">
//<![CDATA[
/* create a Date object called cookieTime to store in the cookie */
var cookieTime = new Date
// prefix a data description string to the data
var cookieData = "recordedCookieTime:" + cookieTime
// create cookie with document.cookie
document.cookie = "testCookie1" + "=" + cookieData + ";path=/"

/* create a Date object called now to compare with the time
stored in the cookie */
var now = new Date
document.write('The time now is: '+ now +'<br />')
// write out the value from the cookie
document.write("Write out the value from the cookie with function getCookie()." + "<br />")
document.write("The function to write out the cookie value is detailed in JavaScript: Cookies code snippet 4." + "<br />")
document.write("The time stored in the cookie is: " + getCookie("testCookie1"))
//]]>
</script>
</body>
</html>