Hướng dẫn dùng timezone offsets trong PHP
What's the easiest way to get the UTC offset in PHP, relative to the current (system) timezone? Show Nội dung chính
Nội dung chính
asked Oct 11, 2008 at 0:58 Adam ErnstAdam Ernst 50.3k18 gold badges58 silver badges71 bronze badges
returns the UTC offset in seconds. answered Oct 11, 2008 at 1:06 4
Ole V.V. 77.5k15 gold badges122 silver badges146 bronze badges answered Mar 15, 2016 at 20:17 2
Untested, but should work answered Oct 11, 2008 at 1:06 John MillikinJohn Millikin 193k39 gold badges211 silver badges222 bronze badges 1 I did a slightly modified version of what Oscar did.
This gave me the offset from my timezone, EST, to UTC, in hours. The value of $utc_offset was -4. answered Jun 9, 2015 at 15:08 KennyKenny 2,1202 gold badges21 silver badges30 bronze badges This is same JavaScript
answered May 29, 2017 at 21:33 زيادزياد 89210 silver badges14 bronze badges 19 Simply you can do this:
answered Mar 23, 2018 at 17:31 HMagdyHMagdy 2,87133 silver badges52 bronze badges 2 This will output something formatted as:
This may be useful for a proper RSS RFC822 format
GMT offsets (like this) shouldn't use a colon ( And, although it is acceptable for RSS RFC833, we don't want output like
answered Apr 7 at 5:23 Jesse יִשַׁיJesse יִשַׁי 6051 gold badge7 silver badges22 bronze badges
And in answered Jan 5, 2013 at 15:55 AmrAmr 4,3536 gold badges44 silver badges58 bronze badges 3 Not the answer you're looking for? Browse other questions tagged php timezone utc or ask your own question.How do I get timezone offset?Definition and Usage getTimezoneOffset() 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. How do I get user time zones?You can set any specific time zone using the PHP function date_default_timezone_set . This sets the specified time zone for users. Basically the users' time zone is goes to the client side, so we must use JavaScript for this. Below is the script to get users' time zone using PHP and JavaScript. How do I get client browser timezone at end of PHP?Detecting the User Timezone Name Detecting the user timezoone is a two-step process: Get the timezone offset of the browser with Javascript, and sent it to PHP (via AJAX or something). Convert the timezone offset to a valid TZ Database timezone name such as America/New_York, Asia/Kolkata. What is offset timezone?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. |