Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

100
Views
Trying to represent date object in another timezone

So basically I have a user enter a date and time for an event start. Later on the user picks a location and I want to display that same time but in a different timezone (For example if the user picks 5PM and picks New York as a location, the UTC date should be 5PM in New York 's timezone).

What I am doing right now is the following:

//utcDate is the date the user picked, I'm just extracting its date and time in this test string, I know this is not how I should parse the string but it is just for test purposes. It returns 2021-29-11 18:00:00. 
const zonedDateString = `${utcDate.getFullYear()}-${utcDate.getMonth()}-${utcDate.getDate()} ${utcDate.getHours()}:${utcDate.getMinutes()}0:00`
//newTimezone is America/New_York, zonedTimeToUtc is a function from date-fns-tz
const newDate = zonedTimeToUtc(zonedDateString, newTimezone) 
// The result for newDate is 2021-11-29T18:00:00Z

Any idea why this isnt working? It is basically just attaching a Z to the end of the string and not adapting it to the timezone.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!