PDA

View Full Version : Help! Current time is not showing up (First time!)



Punny
07-21-2011, 05:09 PM
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.


<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
http://i52.tinypic.com/1zyv7o9.png

I have tried using different browser chrome,IE9,Maxtor, and Opera my OS is Win7

Philip M
07-21-2011, 05:31 PM
<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

nomanic
07-21-2011, 05:33 PM
one big problem is with write



<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

Punny
07-21-2011, 05:55 PM
<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!

http://i53.tinypic.com/xe07r4.png

Oh btw! I am still having error I did what you did.

Punny
07-21-2011, 05:59 PM
one big problem is with write



<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.

nomanic
07-21-2011, 07:24 PM
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
07-21-2011, 07:34 PM
second error - it should be now.toGMTString();

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

full code now becomes -


<script>
now = new Date();
localtime = now.toString();
utctime = now.toGMTString();
document.write("<b>localtime</b>" + localtime + "</br>");
document.write("<b>utctime</b>" + utctime);
</script>

Philip M
07-21-2011, 07:42 PM
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.