javascript help needed!!!
- Started
- Last post
- 17 Responses
- takashi0
something like this:
if (hours>=13)
var dn=""
var hours = "pm "+ (hours-12)
if (hours==24)
var hours = 0
- jevad0
whoah!
- joec0
takashi!!
thank you so much, almost exactly what i needed!! could you tell me what i would need to do to put the "pm" (or "am) after the seconds instead of before the hour?
thanks in advance!!
also, thanks to unformatted and jevad for that link, bookmarked that puppy!
peace
- joe c.
- unformatted0
jevad copied my link you bastard!
- takashi0
if (hours=13)
var dn="pm"
var hours = hours-12
if (hours==24)
var dn="pm"
var hours = 0...but you should look out for a cleaner code for this clock, its not in correct javascript syntax: lacking ";" at end of lines, "{" and "}" at the if statements, lacking of correct script declaration in the script-tag....im not sure if 'your' code will work properly on every machine....do a search in google for 'javascript clock' and pick a proper code.
- takashi0
mmmh...let me have another try:
if (hours=13)
var dn="pm"
var hours = hours-12
if (hours==24)
var dn="pm"
var hours = 0
- takashi0
...and another try:
if (hours<=12)
var dn = "am"
if (hours>=13)
var dn="pm"
var hours = hours-12
if (hours==24)
var dn="pm"
var hours = 0
- takashi0
...sorry had some problems pasting the code in PV-AN, cause of the < and > .
- joec0
ok... i can not thank you enough!!
we are getting closer...
the one small problem it has now is that if the seconds are <9 it still keeps the "0" before the seconds. here is what i have in my code right now:
var dn=""
if (hours=13)
var dn="pm"
var hours = hours-12
if (hours==24)
var dn="pm"
var hours = hours
if (minutes<=9)
minutes="0"+minutes
if (seconds<=9) +"pm "
seconds="0"+secondsi tried playing around with it, but couldnt get the exact thing. can you figure this out? im assuming it will do the same with the minutes...
everything else is working perfectly!!! thanks again...
- mitsu0
here, just use my date function:
paste it in script tags in your body:
function showtime()
{
var dt = new Date();
var hr=dt.getHours();
var mn=(dt.getMinutes()<9)?"0"+dt.ge...
var sc=(dt.getSeconds()<9)?"0"+dt.ge...
var ampm=(hr<12)?"am":"pm";
hr-=12;
window.status=hr+":"+mn+":"+sc+" "+ampm;
setTimeout("showtime()", 250);
}
showtime();
- mitsu0
but change the evaluation in the conditional operator of
getMinutes()<9
to
getMinutes()<=9
that should work
- mitsu0
slightly modified:
this should be correct now...
function showtime()
{
var dt = new Date();
var hr=dt.getHours()-=12;
var mn=(dt.getMinutes()<=9)?"0"+dt.g...
var sc=(dt.getSeconds()<=9)?"0"+dt.g...
var ampm=(dt.getHours()<12)?"am":"pm...
window.status=hr+":"+mn+":"+sc+" "+ampm;
setTimeout("showtime()",50);
}
showtime();
- christianjay0
theres an extension for dreamweaver @ macromedia.com
for a 12hr clock with date.
- takashi0
if i understand the problem:
you want to display a time like 11:03:09 without the "0"?
you want to display it like:
11:3:9 pmis that correct?
- joec0
thanks, everyone for your help!!
the extension that christianjay recommended worked beautifully... fully customizable, works great!! perfect for someone who is still learning js - such as myself! if you guys are ever looking for a quick solution to displaying time and/or date - and are pressed for time, i suggest you check out this kaosweaver extension (its a free download).
once again, thanks for all the help and suggestions, especially takashi!!
peace
- joe c.