Results 1 to 3 of 3

Thread: Storing Client Date/Time

  1. #1
    Join Date
    Feb 2008
    Posts
    74
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Question Storing Client Date/Time

    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!

  2. #2
    Join Date
    Dec 2008
    Location
    Portsmouth, UK
    Posts
    1,891
    Thanks
    2
    Thanked 441 Times in 435 Posts

    Default

    Code:
    <!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>
    Vic
    God Loves You and will never love you less.
    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

  3. The Following User Says Thank You to vwphillips For This Useful Post:

    bigalo (11-05-2009)

  4. #3
    Join Date
    Feb 2008
    Posts
    74
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default

    Thanks so much Vic! this is exactly what I was looking for!

    Cheers!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •