2
Contributors
8
Replies
9
Views
5 Years
Discussion Span
Last Post by cereal
0

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

0

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.

0

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?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.