-1

I want to convert given Date time to local Date time, when input Date time and timeZone is given separately as below

  1. Date -20220120080000 ('yyyymmddHHMMSS')
  2. timezone string -("Australia/Perth")

How to convert above timezone to local Date time without using moment library ?

  • Look here: https://stackoverflow.com/questions/85116/display-date-time-in-users-locale-format-and-time-offset – Samball Mar 10 '22 at 13:37
  • Does this answer your question? [Convert date to another timezone in JavaScript](https://stackoverflow.com/questions/10087819/convert-date-to-another-timezone-in-javascript) – nare214 Mar 10 '22 at 13:38
  • In my case timezone string -("Australia/Perth") is for input date and that I want to convert into local – Ankit Dable Mar 10 '22 at 13:44
  • I don't think the marked duplicate is correct. The OP wants to create a Date for a particular timestamp in a certain location. The duplicate starts with a Date and generates a timestamp for a place with a different offset. A more likely duplicate is [*Calculate Timezone offset only for one particular timezone*](https://stackoverflow.com/questions/61361914/calculate-timezone-offset-only-for-one-particular-timezone). – RobG Mar 11 '22 at 22:39

1 Answers1

0

If you are able to use moment, this becomes pretty straightforward. Check this working example.

let date = "20220120080000";
const format = "YYYYMMDDHHmmss";
let tz = "Australia/Perth";

const remoteTime = moment.tz(date, format, tz);
const localTime = moment(remoteTime).local();