PHP Web Host - Quality Web Hosting For All PHP Applications Just Great Software
  Login or Register
 • Home • Downloads • Your Account • Forums • 

View next topic
View previous topic


Google
 
Web RavenPHPScripts (This Site)
Post new topic   Reply to topic
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 Back to top

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: 545

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

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 Back to top

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())+' '\";
View user's profile Send private message
candy
Worker
Worker


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

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

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!
View user's profile Send private message
Gremmie
Former Moderator in Good Standing


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

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

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.
View user's profile Send private message
candy
Worker
Worker


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

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

thank you so much! that worked for the zeros!
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 13, 2007 4:18 pm Reply with quote Back to top

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
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 13, 2007 5:58 pm Reply with quote Back to top

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())\";
View user's profile Send private message
Display posts from previous:       
Post new topic   Reply to topic

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
Forums ©
 

All logos and trademarks in this site are property of their respective owner.
The comments are property of their posters, all the rest © 2002-2011 by Raven

You can syndicate our news using the file xml

CSE HTML Validator Helped Clean up This Page! [Valid RSS] valid RSS 2.0 Valid robots.txt Stop Spam Harvesters, Join Project Honey Pot

Website engines core code is © copyright by PHP-Nuke but has been heavily patched and modified by myself and others.
PHP-Nuke is a free software released under the GNU/GPL.


:: fisubice phpbb2 style by Daz :: PHP-Nuke theme by www.nukemods.com ::
:: fisubice Theme Modified by the RavenNuke™ Team ::

:: W3C CSS Compliance Validation :: W3C HTML 4.01 Transitional Compliance Validation ::

zerosum