Author |
Message |
candy
Worker


Joined: Dec 21, 2004
Posts: 225
Location: Kansas City metro
|
Posted:
Tue Nov 06, 2007 2:21 pm |
|
hi there. i am looking to change the format of a block i have which displays current time. the issue is i want to be able to display it in 12 hours rather than 24 hour (military time). i would great appreciate help on what to change within the script of the block:
function tS(){ x=new Date(); x.setTime(x.getTime()); return x; }
function lZ(x){ return (x>9)?x:'0'+x; }
function dT(){ window.status='YOUR STATUS BALK TEXT HERE'; if(fr==0){ fr=1; document.write('<font size=2 face= Trebuchet MS><b><span id=\"tP\">'+eval(oT)+'</span></b></font>'); } tP.innerText=eval(oT); setTimeout('dT()',1000); }
var fr=0,oT=\"lZ(tS().getHours())+':'+lZ(tS().getMinutes())+':'+lZ(tS().getSeconds())+' '\"; |
|
|
|
 |
Doulos
Life Cycles Becoming CPU Cycles

Joined: Jun 06, 2005
Posts: 732
|
Posted:
Tue Nov 06, 2007 8:14 pm |
|
wow, I am surprised you got that posted without the blocker going nuts. |
|
|
|
 |
Gremmie
Former Moderator in Good Standing

Joined: Apr 06, 2006
Posts: 2415
Location: Iowa, USA
|
Posted:
Tue Nov 06, 2007 9:08 pm |
|
Off the top of my head, try this (warning, not tested):
Code:
function to12(x)
{
if (x == 0) { return 12; }
return x > 12 ? x - 12 : x;
}
function tS(){ x=new Date(); x.setTime(x.getTime()); return x; }
function lZ(x){ return (x>9)?x:'0'+x; }
function dT(){ window.status='YOUR STATUS BALK TEXT HERE'; if(fr==0){ fr=1; document.write('<font size=2 face= Trebuchet MS><b><span id=\"tP\">'+eval(oT)+'</span></b></font>'); } tP.innerText=eval(oT); setTimeout('dT()',1000); }
var fr=0,oT=\"lZ(to12(tS().getHours()))+':'+lZ(tS().getMinutes())+':'+lZ(tS().getSeconds())+' '\";
|
|
_________________ Only registered users can see links on this board! Get registered or login! - An Event Calendar for PHP-Nuke
Only registered users can see links on this board! Get registered or login! - A Google Maps Nuke Module |
|
|
 |
candy

|
Posted:
Fri Nov 09, 2007 8:19 pm |
|
gremmie-
thank you it worked perfectly! i hate to be a bother, but any idea on how i might now add the AM/PM function and maybe have the first zero not appear if it's 1 - 9 o'clock? Right now when it's 8:20, the clock reads " 08:20". Thanks! |
|
|
|
 |
Gremmie

|
Posted:
Fri Nov 09, 2007 10:06 pm |
|
This will get rid of the leading zeros.
Code:
function to12(x)
{
if (x == 0) { return 12; }
return x > 12 ? x - 12 : x;
}
function tS(){ x=new Date(); x.setTime(x.getTime()); return x; }
function lZ(x){ return (x>9)?x:'0'+x; }
function dT(){ window.status='YOUR STATUS BALK TEXT HERE'; if(fr==0){ fr=1; document.write('<font size=2 face= Trebuchet MS><b><span id=\"tP\">'+eval(oT)+'</span></b></font>'); } tP.innerText=eval(oT); setTimeout('dT()',1000); }
var fr=0,oT=\"to12(tS().getHours())+':'+lZ(tS().getMinutes())+':'+lZ(tS().getSeconds())+' '\";
|
Give me a bit more for the AM/PM. |
|
|
|
 |
candy

|
Posted:
Tue Nov 13, 2007 2:23 pm |
|
thank you so much! that worked for the zeros! |
|
|
|
 |
Gremmie

|
Posted:
Tue Nov 13, 2007 4:18 pm |
|
I haven't forgotten about the AM/PM thing. It isn't hard, I just haven't gotten the time yet to post something.  |
|
|
|
 |
Gremmie

|
Posted:
Tue Nov 13, 2007 5:58 pm |
|
Again, all off the top of my head without being tested:
Code:
function ampm(x)
{
return x < 12 ? 'AM' : 'PM';
}
function to12(x)
{
if (x == 0) { return 12; }
return x > 12 ? x - 12 : x;
}
function tS(){ x=new Date(); x.setTime(x.getTime()); return x; }
function lZ(x){ return (x>9)?x:'0'+x; }
function dT(){ window.status='YOUR STATUS BALK TEXT HERE'; if(fr==0){ fr=1; document.write('<font size=2 face= Trebuchet MS><b><span id=\"tP\">'+eval(oT)+'</span></b></font>'); } tP.innerText=eval(oT); setTimeout('dT()',1000); }
var fr=0,oT=\"to12(tS().getHours())+':'+lZ(tS().getMinutes())+':'+lZ(tS().getSeconds())+' '+ampm(tS().getHours())\";
|
|
|
|
|
 |
|