Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Blocks
Author Message
candy
Worker
Worker



Joined: Dec 21, 2004
Posts: 225
Location: Kansas City metro

PostPosted: Tue Nov 06, 2007 2:21 pm Reply with quote

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())+' '\";
 
View user's profile Send private message
Doulos
Life Cycles Becoming CPU Cycles



Joined: Jun 06, 2005
Posts: 732

PostPosted: Tue Nov 06, 2007 8:14 pm Reply with quote

wow, I am surprised you got that posted without the blocker going nuts.
 
View user's profile Send private message
Gremmie
Former Moderator in Good Standing



Joined: Apr 06, 2006
Posts: 2415
Location: Iowa, USA

PostPosted: Tue Nov 06, 2007 9:08 pm Reply with quote

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())+' '\";

_________________
GCalendar - An Event Calendar for PHP-Nuke
Member_Map - A Google Maps Nuke Module 
View user's profile Send private message
candy







PostPosted: Fri Nov 09, 2007 8:19 pm Reply with quote

gremmie-
thank you it worked perfectly! Smile 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







PostPosted: Fri Nov 09, 2007 10:06 pm Reply with quote

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







PostPosted: Tue Nov 13, 2007 2:23 pm Reply with quote

thank you so much! that worked for the zeros!
 
Gremmie







PostPosted: Tue Nov 13, 2007 4:18 pm Reply with quote

I haven't forgotten about the AM/PM thing. It isn't hard, I just haven't gotten the time yet to post something. Smile
 
Gremmie







PostPosted: Tue Nov 13, 2007 5:58 pm Reply with quote

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())\";
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Blocks

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©