Get time zone information from a date in nodeJS or momentJS

84 Views Asked by At

We have a current time called 11:10 PM as the string value. We will create a date object with this time. Now from this date can we get the timezone for this date value?

We are expecting the timezone like Asia/Kolkata, etc. Is it possible to get this value in NodeJS/MomentJS

1

There are 1 best solutions below

0
Terry Lennox On

You can get the timezone of the machine running the code, using Intl.DateTime.resolvedOptions

If you run this in Node.js you'll get the server timezone, any client running the code in a browser will see their timezone.

// Using Intl
console.log('Timezone: ', Intl.DateTimeFormat().resolvedOptions().timeZone);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.30.1/moment.min.js" integrity="sha512-hUhvpC5f8cgc04OZb55j0KNGh4eh7dLxd/dPSJ5VyzqDWxsayYbojWyl5Tkcgrmb/RVKCRJI1jNlRbVP4WWC4w==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>