TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

April 20, 2024, 12:27:31 AM

Login with username, password and session length
Members
  • Total Members: 3,885
  • Latest: Growner
Stats
  • Total Posts: 195,165
  • Total Topics: 21,219
  • Online today: 118
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 0
  • Guests: 117
  • Total: 117

Time & Date Block

Started by alan s, April 19, 2006, 07:11:23 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

alan s

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 )

IchBin

Here's the php page that explains it all. :)

http://us3.php.net/date

alan s


alan s

i still cant figure out how to add a extra 5 hours though? any more help would be welcome , thanks.

rbh

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>

feral

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

rafynet

#6
Thanks ... Great script RBH ...

I just modified it a little bit ...

  • took out the form element ... i wanted the clock to show in a <div></div> instead of an input box.
  • took out the onpageload="" this makes it easier to put the clock in.
  • just take this code snippet and instert it anywhere in your template or in an html block where you want the date and time.



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