Im creating a time-base site wherein the timestamp should rely on the global time
and not to my PC's time (because it can be out-dated somethimes).
How can I do that?

Unless is specified by localtime(), time_zone cookies and so on, PHP works with the server time, not with client time, if you want to use GMT then use gmdate():

<?php 
echo gmdate('c'); 
echo date('c'); 
?>

http://www.php.net/manual/en/function.gmdate.php

Thanks for the reply. How can it know the time in your location? The time in the east is different from the west.

If the user register to the website you can ask for the timezone location, at that point your script becomes:

<?php 
date_default_timezone_set('Europe/London'); # or America/New_York
echo gmdate('c') . "\n"; 
echo date('c') . "\n"; 
?>

- http://www.php.net/manual/en/function.date-default-timezone-set.php
- http://www.php.net/manual/en/timezones.php

You can also use javascript to get the datetime, send it to your server through ajax and try to figure the timezone. Probably you can also use IP Geolocation but I can't help you on this.

thanks! :D

You're welcome :)

Hello Cereal!

I have some concerns again...

I tried your code:

<?php 
date_default_timezone_set('GMT+8');
echo gmdate('c') . "\n"; 
echo date('c') . "\n"; 
?>

Yes it did show up some dates but the date is still machine date..

2011-29-08, 01.52.45 am //result on gmdate();
2011-08-29T01:52:45+00:00 //result on date();

The exact time now here is 10am.
Seems something is wrong..
What do you think?

i got it! :))

great ;D

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.