What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » JavaScript Localtime

Pages: (2): « First « 1 [ 2 ] Last »
JavaScript Localtime
Author: Message:
Ezra
Veteran Member
*****

Avatar
Forgiveness is between them and God

Posts: 1960
Reputation: 31
37 / Male / Flag
Joined: Mar 2003
RE: JavaScript Localtime
The example was more of something that you could adapt to your website not just copy/paste :P

Because it also uses the direct name of that form, it's better to use getElementById.

So just make a div you want to use for the clock, give it the ID of Clock or something and change that line "ocument.theClock.theTime.value = ...." to something like " document.getElementById("Clock").innerHTML = ..."

Also change the lines after that to make it have the same format as you wanted.
[Image: 1-0.png]
             
04-11-2007 02:48 PM
Profile PM Web Find Quote Report
Eddie
Veteran Member
*****


Posts: 2078
Reputation: 30
32 / Male / Flag
Joined: Oct 2005
Status: Away
O.P. RE: JavaScript Localtime
kty ;)
...there used to be a signature here :)
04-11-2007 02:50 PM
Profile PM Web Find Quote Report
markee
Veteran Member
*****

Avatar

Posts: 1621
Reputation: 50
36 / Male / Flag
Joined: Jan 2006
RE: JavaScript Localtime
I think this is what you are after, I wrote it myself so it might be able to be made smaller (using functions that I don't know about) but it will do.  Just put it in wherever you are wanting the time to be displayed.

code:
<script language="javascript" type="text/javascript" >var d=new Date();var days=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");var months=new Array("January","February","March","April","May","June","July","August","September","October","November","December");document.write(days[d.getDay()]+" "+months[d.getMonth()]+" "+d.getDate()+", "+(d.getYear()+1900)+", "+(d.getHours()%12==0?"12":d.getHours()%12)+":"+(d.getMinutes()>9?d.getMinutes():"0"+d.getMinutes())+(d.getHours()<12?"am":"pm"));</script>


EDIT: should have refreshed the page I guess... and mine is only static, not a dynamic one like that either (it will only show the one time and not continually update... I guess you wanted that though)

EDIT2: fixed my code to have a prefixing 0 on the minutes when they are less than 10 :tongue:

EDIT3: Had a problem with the year that is now fixed.... why do they start at 1900?

This post was edited on 04-12-2007 at 04:15 AM by markee.
[Image: markee.png]
04-11-2007 02:59 PM
Profile PM Find Quote Report
Eddie
Veteran Member
*****


Posts: 2078
Reputation: 30
32 / Male / Flag
Joined: Oct 2005
Status: Away
O.P. RE: JavaScript Localtime
Thanks Markee :) Appreciated buddy :)
...there used to be a signature here :)
04-11-2007 03:33 PM
Profile PM Web Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
31 / Male / Flag
Joined: Apr 2004
RE: JavaScript Localtime
quote:
Originally posted by markee
EDIT3: Had a problem with the year that is now fixed.... why do they start at 1900?
Why don't you simply use d.getFullYear()? Much easier! :D
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
04-14-2007 02:05 PM
Profile E-Mail PM Web Find Quote Report
Pages: (2): « First « 1 [ 2 ] Last »
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On