TinyPortal

Development => Block Codes => Topic started by: alan s on April 19, 2006, 07:11:23 PM

Title: Time & Date Block
Post by: alan s on April 19, 2006, 07:11:23 PM
im using this code


<?php
echo 'Time : ';
echo 
date ('H:i:s');
php echo 'Date:';
echo 
date (' F Y');
?>



to display the time and date but its showing GMT -6 does anyone know what i have to do to set the correct time ( + 5hrs )
Title: Re: Time & Date Block
Post by: IchBin on April 19, 2006, 07:30:28 PM
Here's the php page that explains it all. :)

http://us3.php.net/date
Title: Re: Time & Date Block
Post by: alan s on April 19, 2006, 08:53:21 PM
thanks Ichbin!
Title: Re: Time & Date Block
Post by: alan s on April 19, 2006, 09:41:45 PM
i still cant figure out how to add a extra 5 hours though? any more help would be welcome , thanks.
Title: Re: Time & Date Block
Post by: rbh on April 20, 2006, 03:43:37 PM
you can try this script and see if it is something you want. i use it on one of my sites and it works great. i pieced it together from a couple different scripts i had found a while back.


<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var timerID = null;
var timerRunning = false;
function stopclock (){
if(timerRunning)
clearTimeout(timerID);
timerRunning = false;
}
function showtime () {
var now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds()
var timeValue = "" + ((hours >12) ? hours -12 :hours)
if (timeValue == "0") timeValue = 12;
timeValue += ((minutes < 10) ? ":0" : ":") + minutes
timeValue += ((seconds < 10) ? ":0" : ":") + seconds
timeValue += (hours >= 12) ? " P.M." : " A.M."
document.clock.face.value = timeValue;
timerID = setTimeout("showtime()",1000);
timerRunning = true;
}
function startclock() {
stopclock();
showtime();
}
var months=new Array(13);
months[1]="January";
months[2]="February";
months[3]="March";
months[4]="April";
months[5]="May";
months[6]="June";
months[7]="July";
months[8]="August";
months[9]="September";
months[10]="October";
months[11]="November";
months[12]="December";
var time=new Date();
var lmonth=months[time.getMonth() + 1];
var date=time.getDate();
var year=time.getYear();
if (year < 2000)    // Y2K Fix, Isaac Powell
year = year + 1900; // http://onyx.idbsu.edu/~ipowell
document.write("<center>" + lmonth + " ");
document.write(date + ", " + year + "</center>");
// End -->
</SCRIPT>
<BODY onLoad="startclock()">
<CENTER>
<FORM name="clock">
<input type="text" name="face" size=13 value="">
</FORM>
</CENTER>
Title: Re: Time & Date Block
Post by: feral on April 20, 2006, 11:22:58 PM
the thing with php is that when you use the date() function it pulls the time off the server. if you have access to the the php.ini file you can find the variable date.timezone"", and put your timezone in the "". or you can use a code as such


$h = "5";// Hour for time zone goes here e.g. +7 or -4, just remove the + or -
$hm = $h * 60;
$ms = $hm * 60;
$gmdate = gmdate("m/d/Y g:i:s A", time()-($ms)); // the "-" can be switched to a plus if that's what your time zone is.
echo "Your current time now is :  $gmdate . ";


this code will take the server time and + or - the value that you set(didn't write it, just found it on the net). you can also play with the gmdate so that it displays what you want it to.

hope it helps
Title: Re: Time & Date Block
Post by: rafynet on August 18, 2006, 01:50:44 PM
Thanks ... Great script RBH ...

I just modified it a little bit ...
(https://www.tinyportal.net/smf/index.php?action=dlattach;topic=4468.0;attach=5062;image)


<div id="daClock"></div>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var months=new Array(13);
months[1]="January";
months[2]="February";
months[3]="March";
months[4]="April";
months[5]="May";
months[6]="June";
months[7]="July";
months[8]="August";
months[9]="September";
months[10]="October";
months[11]="November";
months[12]="December";
var time=new Date();
var lmonth=months[time.getMonth() + 1];
var date=time.getDate();
var year=time.getYear();

if (year < 2000)    // Y2K Fix, Isaac Powell
year = year + 1900; // http://onyx.idbsu.edu/~ipowell

var timerID = null;
var timerRunning = false;

function showtime () {
var now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds()
var timeValue = "" + ((hours >12) ? hours -12 :hours)
if (timeValue == "0") timeValue = 12;
timeValue += ((minutes < 10) ? ":0" : ":") + minutes
timeValue += ((seconds < 10) ? ":0" : ":") + seconds
timeValue += (hours >= 12) ? " P.M." : " A.M."
document.getElementById("daClock").innerHTML = lmonth + " " + date + ", " + year + " &nbsp;&nbsp; " + timeValue;
timerID = setTimeout("showtime()",1000);
timerRunning = true;
}

showtime();
// End -->
</SCRIPT>