Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: get Date

  1. #1
    New to the CF scene
    Join Date
    Dec 2011
    Location
    London
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question get Date

    Hi,
    i need to get the current date into some format so that it doesn't change?
    here i have some code:
    Code:
    function printTime(){
    var d=new Date();
    var utc = d.toUTCString();
    alert(utc);
    }
    for example this show for me: Mon, 26 Dec 2011 21:55:43 GMT

    I would like to get this information again, lets say 5 minutes later - but i want the information to still read Mon, 26 Dec 2011 21:55:43 GMT not Mon, 26 Dec 2011 22:00:43 GMT for example

    Any help greatly appreciated

  • #2
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,146
    Thanks
    39
    Thanked 505 Times in 499 Posts

    Question

    Quote Originally Posted by Laurence485 View Post
    Hi,
    i need to get the current date into some format so that it doesn't change?
    here i have some code:
    Code:
    function printTime(){
    var d=new Date();
    var utc = d.toUTCString();
    alert(utc);
    }
    for example this show for me: Mon, 26 Dec 2011 21:55:43 GMT

    I would like to get this information again, lets say 5 minutes later - but i want the information to still read Mon, 26 Dec 2011 21:55:43 GMT not Mon, 26 Dec 2011 22:00:43 GMT for example

    Any help greatly appreciated
    I don't understand your request...

    You want to display the same date, but not the same time?
    And you want the time to be earlier than before after a 5 minute delay?

    If that is what you want, form you date display to a global variable.
    Then display it as many times as you want anywhere you want.
    Until you change the variable, it will display the same thing each time!

  • #3
    New to the CF scene
    Join Date
    Dec 2011
    Location
    London
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by jmrker View Post
    I don't understand your request...

    You want to display the same date, but not the same time?
    And you want the time to be earlier than before after a 5 minute delay?

    If that is what you want, form you date display to a global variable.
    Then display it as many times as you want anywhere you want.
    Until you change the variable, it will display the same thing each time!
    hi i want to display the same date and the same time i.e. no matter how many times i call alert(utc) it will always show exactly the same date and same time.
    Code:
    function printTime(){
    var d=new Date();
    var utc = d.toUTCString();
    alert(utc);
    alert(utc);
    alert(utc);
    }
    i want utc to be the same value each time it is called. So for example:
    Mon, 26 Dec 2011 21:55:43 GMT
    Mon, 26 Dec 2011 21:55:43 GMT
    Mon, 26 Dec 2011 21:55:43 GMT

  • #4
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,146
    Thanks
    39
    Thanked 505 Times in 499 Posts

    Lightbulb

    Still see little use for it, but here your go...
    Code:
    <!DOC HTML>
    <html>
    <head>
    <title> Untitled </title>
    <script type="text/javascript">
    var utc = new Date().toUTCString();
    function printTime(){
      alert(utc);
      alert(utc);
      alert(utc);
    }
    </script>
    
    </head>
    <body>
    <button onclick="printTime()">Print time</button>
    <button onclick="printTime()">Print time again!</button>
    <button onclick="printTime()">One more time</button>
    </body>
    </html>

  • Users who have thanked jmrker for this post:

    Laurence485 (12-27-2011)

  • #5
    New to the CF scene
    Join Date
    Dec 2011
    Location
    London
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Thumbs up

    Quote Originally Posted by jmrker View Post
    Still see little use for it, but here your go...
    Code:
    <!DOC HTML>
    <html>
    <head>
    <title> Untitled </title>
    <script type="text/javascript">
    var utc = new Date().toUTCString();
    function printTime(){
      alert(utc);
      alert(utc);
      alert(utc);
    }
    </script>
    
    </head>
    <body>
    <button onclick="printTime()">Print time</button>
    <button onclick="printTime()">Print time again!</button>
    <button onclick="printTime()">One more time</button>
    </body>
    </html>
    modified your code a bit to get it for what i required. The purpose for it is to let the user know what time they started using an application.
    thanks for your help

  • #6
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,146
    Thanks
    39
    Thanked 505 Times in 499 Posts

    Thumbs up

    Quote Originally Posted by Laurence485 View Post
    modified your code a bit to get it for what i required. The purpose for it is to let the user know what time they started using an application.
    thanks for your help
    You're most welcome.
    Happy to help.

    I find most would use it to determine how long the user had been on page.
    That would be determined by subtracting the start time from the current time.
    But, if that's they way you wish it to be displayed, Good Luck!


  •  

    Posting Permissions

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