2

Possible Duplicate:
Guessing User's TimeZone in PHP

How can i get my system current time zone in php thanks in advance I tried this code

echo date_default_timezone_get();
echo date('H:i:s');
date_default_timezone_set('GMT');
echo date_default_timezone_get();
echo date('H:i:s');

but i got

**UTC
07:51:52

GMT
07:51:52**

also i tried date('Z'); i got

0

but my time zone is asia/kolkatta

Community
  • 1
  • 1
Riya
  • 529
  • 4
  • 10
  • 18
  • 1
    you need to provide the $timezone_identifier to the function http://php.net/manual/en/function.date-default-timezone-set.php – Neo May 30 '12 at 08:01
  • can i get timezone without that because my current requirment is depend upon system time – Riya May 30 '12 at 08:03
  • check it out from http://stackoverflow.com/questions/3595164/get-server-time-in-php-timezone-issues – Neo May 30 '12 at 08:04
  • 1
    "my system time zone" -- what do you mean by that? Server's timezone? – zerkms May 30 '12 at 08:16
  • @ zerkms:timezone of local machine – Riya May 30 '12 at 08:27
  • You cannot get the timezone of the remote system (the client, *your* system), because the client does not typically send that information to the server. What problem are you trying to solve? – deceze May 30 '12 at 08:35
  • 1
    @deceze :when iam sending a meeting invite from india(or any other cuntry) the person who is receiving the invite must see the meeting time as london time.Plz help me out – Riya May 30 '12 at 08:42
  • 2
    Then ask each user what timezone he's in. That's pretty standard practice for calendaring software. – deceze May 30 '12 at 08:43

2 Answers2

3

You should send all time information as UTC, then if the local machine has its system clock set correctly it can be converted to a local time. There are some functions here for converting to and from UTC on a local machine in javascript. Your server should only work in UTC.

Community
  • 1
  • 1
RobG
  • 142,382
  • 31
  • 172
  • 209
2

PHP doesn't know anything about server's timezone. date_default_timezone_get() function returns value from php.ini or if it was set by date_default_timezone_set();

You can get it from command line using date on *nix or tzutil on Windows.

a.tereschenkov
  • 807
  • 4
  • 10