问题
I want to get timezone of visitors of my application in UTC format like (UTC+05:00) in php or javascript.
I have already tried this but it does not help me out it returns the result as Asia/Karachi:
$time ="<script>document.write(Intl.DateTimeFormat().resolvedOptions().timeZone);</script>";
echo $time;
Result: Asia/Karachi
I want to get result in UTC format like (UTC+05:00). How can I achieve this?
回答1:
Here is a javascript solution :
let date = new Date();
console.log('UTC' +
(-date.getTimezoneOffset() < 0 ? '-' : '+') +
(Math.abs(date.getTimezoneOffset() / 60) < 10 ? '0' : '') +
(Math.abs(date.getTimezoneOffset() / 60)) + ':00'
);
来源:https://stackoverflow.com/questions/55903592/how-to-get-client-timezone-in-utc-format-like-utc0500-in-php-or-javascript