Hi,
I need to put a time on my website which simply shows the current GMT London time...

I tried using <? echo date("g:ia") ?> but for some reason it displays the time exactly one hour ahead of my time. It should be displaying Europe/London time. (I do live in the London time zone)
I've also tried gmtime(); etc etc. but nothing seems to work.


Does anyone know how I should do this?

I'd really appreciate some help.

Martin

are you trying to display the date or time? or both?

Have you tried a simple output??
<?php
echo date("m/d/y");
?>

If that doesnt work try this:

//get the current server date as timestamp
$dat = mktime(date("G"), date("i"), date("s"), date("n"), date("j"), date("Y"));
//work out seconds difference
$difference = substr(date("O",$dat),1,2);
$datdif = 60 * 60 * $difference;
//add or subtract seconds where necessary
if (substr(date("O",$dat),0,1) == '+') {
$dat = $dat - $datdif;
}
else {
$dat = $dat + $datdif;
}
//output date in hh:mm:ss format
echo date("H:i:s", $dat);
?>

If these dont work let me know...theres a few more ways to try.

Thank you :-)

I've been struggling with that for so long :->

I've simplified it a bit as well so that it can just subtract one hour from the current timestamp (if this is any help to anyone else) :

<?
//get current timestamp and subtract one hour
$dat = time() - 3600;
//output time
echo date("g:ia", $dat);
?>

Thanks again,
Martin

I tried the sample code, and it does make the time show correctly, one hour behind. But when it gets to 11:00 pm, it changes the date and causes problems. Is there a foolproof way to solve this?

Thank you.

use this:

date_default_timezone_set('GMT');

Tested and works.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.