PDA

View Full Version : Storing Client Date/Time



bigalo
11-04-2009, 05:37 PM
Hello,

I hope someone can help. I know on the front end using js you can get the date and time on client machine and store in a hidden field so it can be grabbed to use on the back-end to store in a database or even return a special message based on their time. However, I'm not too sure how to begin. Would anyone happen to have any idea on how to do this?


Thanks in advanced!

vwphillips
11-05-2009, 03:59 PM
<!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">

<head>
<title></title>
<script type="text/javascript">
/*<![CDATA[*/
function Format(nu){
return nu>9?nu:'0'+nu;
}
function Time(){
var today=new Date();
var year=today.getFullYear();
var month=Format(today.getMonth()+1);
var date=Format(today.getDate());
var hour=Format(today.getHours());
var minutes=Format(today.getMinutes());
var seconds=Format(today.getDate());
document.forms[0].ClientTime.value=year+'-'+month+'-'+date+'-'+hour+'-'+minutes+'-'+seconds;
}
/*]]>*/
</script></head>

<body>
<form>
<input name="ClientTime" size="42"/>
</form>
<script type="text/javascript">
/*<![CDATA[*/
Time();
/*]]>*/
</script>

</body>

</html>

bigalo
11-05-2009, 04:32 PM
Thanks so much Vic! this is exactly what I was looking for!

Cheers!