Convert Date to Another Timezone in JavaScript

preview_player
Показать описание
---

Convert Date to Another Timezone in JavaScript

Using the Built-In JavaScript Date Object

JavaScript's Date object is designed to work with the local timezone by default. However, you can convert dates to different timezones using some built-in methods and the Intl.DateTimeFormat object.

Converting to UTC

To convert a local date to UTC, you can use the toUTCString() method:

[[See Video to Reveal this Text or Code Snippet]]

Converting to a Specific Timezone

For converting to a specific timezone, you can use the Intl.DateTimeFormat object, which provides a way to format dates based on different locales and timezones:

[[See Video to Reveal this Text or Code Snippet]]

Getting the Timezone Offset

To get the timezone offset in minutes, you can use the getTimezoneOffset() method:

[[See Video to Reveal this Text or Code Snippet]]

[[See Video to Reveal this Text or Code Snippet]]

Converting to Another Timezone

[[See Video to Reveal this Text or Code Snippet]]

Parsing and Formatting Dates

[[See Video to Reveal this Text or Code Snippet]]

Conclusion

Рекомендации по теме