Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UTC Offset in PHP

Tags:

timezone

php

utc

What's the easiest way to get the UTC offset in PHP, relative to the current (system) timezone?

like image 934
Adam Ernst Avatar asked Oct 11 '08 00:10

Adam Ernst


People also ask

What is UTC timezone PHP?

The default timezone for PHP is UTC regardless of your server's timezone. This is the timezone used by all PHP date/time functions in your scripts. To change the PHP timezone for an app, create a .user.ini file in the app's public directory with the following contents: date.timezone = America/Los_Angeles.

How do I get timezone offset?

Definition and UsagegetTimezoneOffset() returns the difference between UTC time and local time. getTimezoneOffset() returns the difference in minutes. For example, if your time zone is GMT+2, -120 will be returned.

What is timezone offset?

What is a "zone offset"? A zone offset is the difference in hours and minutes between a particular time zone and UTC. In ISO 8601, the particular zone offset can be indicated in a date or time value. The zone offset can be Z for UTC or it can be a value "+" or "-" from UTC.


2 Answers

  date('Z');

returns the UTC offset in seconds.

like image 142
Czimi Avatar answered Oct 18 '22 23:10

Czimi


// will output something like +02:00 or -04:00
echo date('P');
like image 49
Tuhin Bepari Avatar answered Oct 18 '22 22:10

Tuhin Bepari