note 125626 added to function.date-default-timezone-get
| From: | smcbride at msn dot com | Date: | Thu, 24 Dec 2020 14:09:38 +0000 |
| Subject: | note 125626 added to function.date-default-timezone-get | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-216017@lists.php.net to get a copy of this message | ||
This function is not very useful for getting the OS timezone. One way to do it is to look at the
results of 'timedatectl' from the OS. You can also look at the link from /etc/localtime
>file /etc/localtime
/etc/localtime: symbolic link to /usr/share/zoneinfo/America/Los_Angeles
>timedatectl
Local time: Thu 2020-12-24 07:11:27 PST
Universal time: Thu 2020-12-24 15:11:27 UTC
RTC time: Thu 2020-12-24 15:11:27
Time zone: America/Los_Angeles (PST, -0800)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
<?php
$dateinfo = trim(shell_exec("timedatectl | grep -i zone: 2>/dev/null"));
$dateinfoarray = explode(' ', $dateinfo);
echo 'Timezone = ' . $dateinfoarray[2] . PHP_EOL;
?>
----
Server IP: 45.112.84.4
Probable Submitter: 45.91.159.165 (proxied: 107.77.213.138)
----
Manual Page -- http://php.net/manual/en/function.date-default-timezone-get.php
Edit -- https://master.php.net/note/edit/125626
Del: integrated -- https://master.php.net/note/delete/125626/integrated
Del: useless -- https://master.php.net/note/delete/125626/useless
Del: bad code -- https://master.php.net/note/delete/125626/bad+code
Del: spam -- https://master.php.net/note/delete/125626/spam
Del: non-english -- https://master.php.net/note/delete/125626/non-english
Del: in docs -- https://master.php.net/note/delete/125626/in+docs
Del: other reasons-- https://master.php.net/note/delete/125626
Reject -- https://master.php.net/note/reject/125626
Search -- https://master.php.net/manage/user-notes.php