Dils Umesha Dils Umesha - 1 month ago 6
PHP Question

Timezone convert

this is my requirement.website admin add a time to an event. Then users will see that time according to user's current location time.

And this php code to convert any time to user current location's time.

<?php
$date = date_create('2000-01-01',timezone_open('Pacific/Nauru'));
date_timezone_set($date,timezone_open('Europe/Moscow'));
echo date_format($date, 'Y-m-d H:i:sP') . "\n";
?>


How to determine user timezone (ex:Europe/Moscow)

I have this js code to get timezone of user current location.

<script>
var visitortime = new Date();
var time = visitortime.getTimezoneOffset()/60;
alert(time);
</script>


But it alert a number(ex:+5.5)
Can you help me please

Answer

Use this code to get current users timezone.

var timezone = Intl.DateTimeFormat().resolvedOptions().timeZone
Comments