Time Zones

When setting a date, without specifying the time zone, JavaScript will use the browser’s time zone.

When getting a date, without specifying the time zone, the result is converted to the browser’s time zone.

In other words: If a date/time is created in GMT (Greenwich Mean Time), the date/time will be converted to CDT (Central US Daylight Time) if a user browses from central US.

Example

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript new Date()</h2>

<p id="demo"></p>

<script>
const d = new Date("Oct 01 2023");
document.getElementById("demo").innerHTML = d;
</script>

</body>
</html>

Output

JavaScript new Date()
Sun Oct 01 2023 00:00:00 GMT+0530 (India Standard Time)

Thanks.

By Soronix

Leave a Reply

Your email address will not be published. Required fields are marked *