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

339
Views
wrong date on conversion toISOString()

I am confused why on converting 8/20/2021 to ISO (cosmosDB format) I am getting 2021-08-19T18:30:00.000Z

const event = new Date('8/20/2021');
console.log(event.toISOString()); //"2021-08-19T18:30:00.000Z"

all the date are saved as string in my cosmosdb and hence I was not able to filter based on given date range and as result we ended up converting string to Date but now when I am trying to convert in to cosmos db expected format it gives me incorrect or may be correct date to update my database.

should I go ahead and update DB to 2021-08-19T18:30:00.000Z in place of 8/20/2021? or it should be 2021-08-20T00:00:00.000Z?

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

0

The value you are passing to Date() is vague. It's being parsed as a date for the timezone for the computer's locale.

When you convert to an ISO string, it's being displayed in UTC, which is 5 and a half hours behind that local time zone.

  • Be more specific when you pass the string to Date()
  • Consider converting the date to the user's local time zone when you read it back from the database
about 4 years ago · Juan Pablo Isaza Report

0

The Date.parse() method parses a string representation of a date, and returns the number of milliseconds since January 1, 1970, 00:00:00 UTC

Try this

const event = Date.parse('8/20/2021');
console.log(event) // expected output: 818035920000

Now you can store that in your db.

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!