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 8 of 8
  1. #1
    New Coder
    Join Date
    Apr 2011
    Posts
    12
    Thanks
    2
    Thanked 1 Time in 1 Post

    Help! Current time is not showing up (First time!)

    This is my first time doing JavaScript I don't what I did wrong here, but the problem its not showing up the current date and time.
    Code:
    <script language = "JavaScript" type="text/javascript"> 
    now = new Date(); 
    localtime = now.toString();
     utctime = now.GMTString();
     document.wite("<b>localtime</b>" + localtime + "</br>");
     document.write("<b>utctime</b>" + utctime); 
     </script>
    This is what supposed to look like


    I have tried using different browser chrome,IE9,Maxtor, and Opera my OS is Win7
    Last edited by Punny; 07-21-2011 at 04:11 PM.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,731
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    Code:
    <script type="text/javascript"> 
    var now = new Date(); 
    var localtime = now.toString();
    var utctime = now.toUTCString();
    document.write("<b>localtime</b>" + localtime + "</br>");
    document.write("<b>utctime</b>" + utctime); 
    </script>

    "Never attribute to malice that which can be adequately explained by stupidity." - Napoleon Bonaparte

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    Regular Coder nomanic's Avatar
    Join Date
    Feb 2009
    Location
    United Kingdom
    Posts
    255
    Thanks
    9
    Thanked 33 Times in 33 Posts
    one big problem is with write

    Code:
    <script language = "JavaScript" type="text/javascript"> 
    now = new Date(); 
    localtime = now.toString();
     utctime = now.GMTString();
     document.write("<b>localtime</b>" + localtime + "</br>");
     document.write("<b>utctime</b>" + utctime); 
     </script>
    first document write was document.wite, it wont work

  • #4
    New Coder
    Join Date
    Apr 2011
    Posts
    12
    Thanks
    2
    Thanked 1 Time in 1 Post
    Quote Originally Posted by Philip M View Post
    Code:
    <script type="text/javascript"> 
    var now = new Date(); 
    var localtime = now.toString();
    var utctime = now.toUTCString();
    document.write("<b>localtime</b>" + localtime + "</br>");
    document.write("<b>utctime</b>" + utctime); 
    </script>

    "Never attribute to malice that which can be adequately explained by stupidity." - Napoleon Bonaparte

    Don't call me stupid I'm simply following a tutorial if you want to call something stupid its the tutorial I been reading. Did I even mention I am still a novice? What an asshole!



    Oh btw! I am still having error I did what you did.
    Last edited by Punny; 07-21-2011 at 04:57 PM.

  • #5
    New Coder
    Join Date
    Apr 2011
    Posts
    12
    Thanks
    2
    Thanked 1 Time in 1 Post
    Quote Originally Posted by nomanic View Post
    one big problem is with write

    Code:
    <script language = "JavaScript" type="text/javascript"> 
    now = new Date(); 
    localtime = now.toString();
     utctime = now.GMTString();
     document.write("<b>localtime</b>" + localtime + "</br>");
     document.write("<b>utctime</b>" + utctime); 
     </script>
    first document write was document.wite, it wont work
    I made the change but I am still having the problem its not showing the time and date.

  • #6
    Regular Coder nomanic's Avatar
    Join Date
    Feb 2009
    Location
    United Kingdom
    Posts
    255
    Thanks
    9
    Thanked 33 Times in 33 Posts
    Philip isnt calling you stupid Punny, that comment gets printed everytime he makes a comment, to everyone, its just a comment in his footer. Hes making an observation on life, not you.

  • #7
    Regular Coder nomanic's Avatar
    Join Date
    Feb 2009
    Location
    United Kingdom
    Posts
    255
    Thanks
    9
    Thanked 33 Times in 33 Posts
    second error - it should be now.toGMTString();

    but as Philip suggests maybe your code suggests you should use
    now.toUTCString();

    full code now becomes -
    Code:
    <script>
    now = new Date();
    localtime = now.toString();
     utctime = now.toGMTString();
     document.write("<b>localtime</b>" + localtime + "</br>");
     document.write("<b>utctime</b>" + utctime);
     </script>

  • #8
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,731
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    The code I gave you works for me and results in

    localtimeThu Jul 21 18:34:56 UTC+0100 2011
    utctimeThu, 21 Jul 2011 17:34:56 UTC

    toGMTString is deprecated - use toUTCString instead.
    <script language="javascript"> is long deprecated and obsolete. Use <script type = "text/javascript"> instead.


    And no, I was not getting at you personally. As nomadic says, it was just one of my stock observations on life, not you.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

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