note 127119 added to datetimezone.getoffset

From: Date: Thu, 19 May 2022 20:32:16 +0000
Subject: note 127119 added to datetimezone.getoffset
Groups: php.notes 
Request: Send a blank email to php-notes+get-218506@lists.php.net to get a copy of this message
I came here looking for a way to get the offset between PHP's current default timezone and UTC. I went down the rabbit hole with DateTimeZone::getOffset, but it turns out there's a much easier way: <?php $offset = date('O'); // Returns a string like '-0400' $offset = date('P'); // Returns a string like '-04:00' $offset = date('Z'); // Returns the offset in seconds, e.g. '-14400' ?> To be clear, this gets whatever the timezone offset is *right now*, but I imagine that's what is wanted most of the time. You can switch PHP's current timezone with date_default_timezone_set(). ---- Server IP: 45.112.84.4 Probable Submitter: 185.85.3.47 (proxied: 163.116.147.39) ---- Manual Page -- https://php.net/manual/en/datetimezone.getoffset.php Edit -- https://main.php.net/note/edit/127119 Del: integrated -- https://main.php.net/note/delete/127119/integrated Del: useless -- https://main.php.net/note/delete/127119/useless Del: bad code -- https://main.php.net/note/delete/127119/bad+code Del: spam -- https://main.php.net/note/delete/127119/spam Del: non-english -- https://main.php.net/note/delete/127119/non-english Del: in docs -- https://main.php.net/note/delete/127119/in+docs Del: other reasons-- https://main.php.net/note/delete/127119 Reject -- https://main.php.net/note/reject/127119 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#218506) next »