How to get the current date time of other countries in JavaScript
📅November 22, 2021
In this article, we will show you how to get the current date time of other countries in JavaScript. Here we will give you an example to get Dubai’s current datetime" title="DateTime">DateTime using JavaScript.
Checkout more articles on JavaScript
- file-using-javascript" title="Download a file using JavaScript">Download a file using JavaScript
- array-contains-any-element-of-another-array-in-javascript" title="Check if an array contains any element of another array in JavaScript">Check if an array contains any element of another array in JavaScript
- How to get the web page size in JavaScript
- moment-js" title="Time from now using Moment JS">Time from now using Moment JS
- Get Current Date & Time in JavaScript
Code snippet to get the current datetime of other country
const d = new Date();
const localTime = d.getTime();
const localOffset = d.getTimezoneOffset() * 60000;
const utc = localTime + localOffset;
const offset = 4; // UTC of Dubai is +04.00
const dubai = utc + (3600000 * offset);
const dubaiTimeNow = new Date(dubai).toLocaleString();
// Output: 11/22/2021, 11:07:27 AM
In the above example, the `4` is the Dubai’s Time Zone">time zone offset. You can also achieve the same things via Moment.js.
I hope you find this article helpful.
Thank you for reading. Happy Coding..!! 🙂