Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-21-2011, 04:09 PM   PM User | #1
Punny
New Coder

 
Join Date: Apr 2011
Posts: 12
Thanks: 2
Thanked 1 Time in 1 Post
Punny is an unknown quantity at this point
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..
Punny is offline   Reply With Quote
Old 07-21-2011, 04:31 PM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,033
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
Philip M is offline   Reply With Quote
Old 07-21-2011, 04:33 PM   PM User | #3
nomanic
Regular Coder

 
nomanic's Avatar
 
Join Date: Feb 2009
Location: United Kingdom
Posts: 252
Thanks: 9
Thanked 33 Times in 33 Posts
nomanic is an unknown quantity at this point
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
nomanic is offline   Reply With Quote
Old 07-21-2011, 04:55 PM   PM User | #4
Punny
New Coder

 
Join Date: Apr 2011
Posts: 12
Thanks: 2
Thanked 1 Time in 1 Post
Punny is an unknown quantity at this point
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..
Punny is offline   Reply With Quote
Old 07-21-2011, 04:59 PM   PM User | #5
Punny
New Coder

 
Join Date: Apr 2011
Posts: 12
Thanks: 2
Thanked 1 Time in 1 Post
Punny is an unknown quantity at this point
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.
Punny is offline   Reply With Quote
Old 07-21-2011, 06:24 PM   PM User | #6
nomanic
Regular Coder

 
nomanic's Avatar
 
Join Date: Feb 2009
Location: United Kingdom
Posts: 252
Thanks: 9
Thanked 33 Times in 33 Posts
nomanic is an unknown quantity at this point
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.
nomanic is offline   Reply With Quote
Old 07-21-2011, 06:34 PM   PM User | #7
nomanic
Regular Coder

 
nomanic's Avatar
 
Join Date: Feb 2009
Location: United Kingdom
Posts: 252
Thanks: 9
Thanked 33 Times in 33 Posts
nomanic is an unknown quantity at this point
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>
nomanic is offline   Reply With Quote
Old 07-21-2011, 06:42 PM   PM User | #8
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,033
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
Philip M is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:16 PM.


Advertisement
Log in to turn off these ads.