Page 1 of 1

Modify date() to give gmt

Posted: Mon Jan 12, 2004 6:08 am
by Shendemiar
<?php
echo (date("G:i , D d M Y"));
?>

This gives the time of the computer runned in.

Is there a easy way to modify the hours date results, something like date("G+5:i , D d M Y")

Posted: Mon Jan 12, 2004 6:12 am
by Weirdan

Code: Select all

echo date("G:i , D d M Y",strtotime("now +5 hours"));

Posted: Mon Jan 12, 2004 6:15 am
by Shendemiar
:? :) :o :D :lol:

Thanks!

Posted: Mon Jan 12, 2004 6:23 am
by Shendemiar
Gives nice gmt time.

Code: Select all

echo date("G:i",strtotime("now +6 hours"))." GMT, ".date("D d M Y");

Posted: Mon Jan 12, 2004 8:02 pm
by Shendemiar
Now the dates go wrong...

Anyone know easy script to receive GMT or to enhance date() so that the date part also realizes the timedifference?

Posted: Wed Jan 14, 2004 7:18 am
by Shendemiar
I'm using this currently, seems to work, but i havent verified the date-thing yet.

echo 'GMT: '.gmdate("G:i, D d M Y",time() + (3600 * $timezone));

Posted: Wed Jan 14, 2004 7:42 am
by Gen-ik
Using something like gmdate("jS F Y") will give you the GMT date (like you've done above).

You only need to add any additional code if you want to get time-offsets from GMT... for example gmdate("jS F Y", strtotime("+1 hour", time())) would give you the time in Paris (or GMT + 1)

Posted: Wed Jan 14, 2004 8:06 am
by Shendemiar
I had that kind earlier, but it didnt work: adding hours to time just resulted strange hours if the server was on different day than the viewer.

Posted: Wed Jan 14, 2004 9:56 am
by Gen-ik
That's strange, it's always worked for me. By default time() will/should give you a unix-timestamp (time of seconds since January 1 1970 00:00:00 GMT) which by default is GMT as you can see.

Might be worth checking out [php_man]date[/php_man] [php_man]time[/php_man] and [php_man]mktime[/php_man] in the manual.

Posted: Wed Jan 14, 2004 10:17 am
by Shendemiar
You're correct. i didnt had exactly that you suggested but

Code: Select all

echo date("G:i , D d M Y",strtotime("now +5 hours"));
instead.



But now i'm allready much more wiser

Posted: Wed Jan 14, 2004 12:44 pm
by Gen-ik
Glad to be of help :)

I remember that the whole PHP date thing confused me a bit when I first started using PHP... it's not too bad once you get used to all the different date/time formats though.

Good luck.