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

221
Views
Passing a string to new Date() constructor results in Invalid Date

How can I pass a string date from a variable to the new Date(...) constructor? The following code produces Invalid Date. Do I need to convert it first somehow?

var dateString = '18/11/2021';
var dateObject = new Date(dateString);
alert(dateObject);

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

0

When using the Date(dateString) constructor, the date string must be specified in simplified ISO 8601 date format. Also note that conforming date only formats such as yyyy-mm-dd are treated as UTC, not local. The following should produce the expected result:

alert(new Date("2021-11-18T00:00:00"));

Using any non-standard format is discouraged and the results are implementation specific.

about 4 years ago · Juan Pablo Isaza Report

0

it's your dateString format. First the year, month and then day.

hello = '2021/11/18';
end = new Date(hello);
alert(end);

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!