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

164
Views
Angular converting string to date error invalid

I am getting a date in the form of string date: '2022-07-15T09:29:24.958922Z[GMT]', When I convert it in to date then I get error invalid date. Does someone know how to solve it?

   const myDate = response; // '2022-07-15T09:29:24.958922Z[GMT]'
   this.transactionDate = new Date(myDate);

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

So the problem is [GMT] in your response string.

Either your response should be something like this

new Date("Fri Jan 20 2022 11:51:36 GMT-0500")

or you need to remove [GMT] from your existing string

 var datestring ='2022-07-15T09:29:24.958922Z[GMT]';
 datestring.substr(0,datestring.indexOf('['));
 new Date(datestring)

var withGMT = new Date("Fri Jan 22 2022 11:51:36 GMT-0500")
console.log(withGMT);

var dateString ='2022-07-15T09:29:24.958922Z[GMT]';
var withoutGMT=dateString.substr(0,dateString.indexOf('['));
console.log(new Date(withoutGMT))

about 4 years ago · Santiago Gelvez 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!