Login  |  Register
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome, Guest. Please login or register.
Did you miss your activation email?

August 19, 2022, 05:49:27 AM

Login with username, password and session length
Members
  • Total Members: 3843
  • Latest: Tricky
Stats
  • Total Posts: 193479
  • Total Topics: 21088
  • Online today: 58
  • Online ever: 1035
  • (November 26, 2020, 04:45:12 AM)
Users Online
Users: 1
Guests: 58
Total: 59

Author Topic: Time & Date Block  (Read 8613 times)

0 Members and 1 Guest are viewing this topic.

alan s

  • Guest
Time & Date Block
« on: April 19, 2006, 12:11:23 PM »
im using this code

Code: [Select]

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

Offline IchBin

  • Friends
  • *
  • Posts: 16231
Re: Time & Date Block
« Reply #1 on: April 19, 2006, 12:30:28 PM »
Here's the php page that explains it all. :)

http://us3.php.net/date

alan s

  • Guest
Re: Time & Date Block
« Reply #2 on: April 19, 2006, 01:53:21 PM »
thanks Ichbin!

alan s

  • Guest
Re: Time & Date Block
« Reply #3 on: April 19, 2006, 02:41:45 PM »
i still cant figure out how to add a extra 5 hours though? any more help would be welcome , thanks.

rbh

  • Guest
Re: Time & Date Block
« Reply #4 on: April 20, 2006, 08:43:37 AM »
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.


Code: [Select]
<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

  • Guest
Re: Time & Date Block
« Reply #5 on: April 20, 2006, 04: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

Code: [Select]
$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

  • Guest
Re: Time & Date Block
« Reply #6 on: August 18, 2006, 06:50:44 AM »
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.


Code: [Select]
<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>

« Last Edit: August 18, 2006, 06:57:53 AM by rafynet »