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

189
Views
Javascript parse all day date YYYY-MM-DD in my timezone

Suppose I create an all day event for Christmas day. I want this event to be 25 Dec regardless of which timezone you are in. I store the event date as "2023-12-25" on the server.

When I do new Date("2023-12-25") in the browser it's interpreted as a UTC date which is not what I want, for example if I'm in New York and I do

new Date("2023-12-25") // Sun Dec 24 2023 19:00:00 GMT-0500 (Eastern Standard Time)

Which means when I go to format the all day event it will format as 24 December which is not what I want.

Desired behaviour:

// If in New York
parseAllDayDate("2023-12-25") // Sun Dec 25 2023 00:00:00 GMT-0500 (Eastern Standard Time)

// If in London
parseAllDayDate("2023-12-25") // Mon Dec 25 2023 00:00:00 GMT+0000 (Greenwich Mean Time)

Also, please don't suggest dayjs or momentjs I would like to do this just with JS Date.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can try this

parseAllDayDate(dateString) {
    let dateStringSplit = dateString.split('-');
    let date = new Date();
    date.setUTCDate(dateStringSplit[2]);
    date.setUTCMonth(dateStringSplit[1]);
    date.setUTCFullYear(dateStringSplit[0]);
    return date;
}

about 4 years ago · Juan Pablo Isaza Report
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!