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?
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' );
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.