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

293
Views
How to convert a string to a date in angular

How to covert a string to a date in Angular13?

For example: str = '2022-06-09T22:00:00Z'; to a datetime mm/dd/yyyy --:-- --

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

0

If you are okay with using a library, I would recommend to use moment.js. Here's a link!

Firstly, since we can not access the inbuilt functions from a string, we need to convert it to a date:

var date = new Date("2022-06-09T22:00:00Z")

Using moment.js:

moment.utc(d).format('MM/DD/YYYY HH:mm:ss')     // -> 06/09/2022 22:00:00

Using standard in-built functions:

var formatted = ("0"+(d.getUTCMonth()+1)).slice(-2) + "/" + ("0" + d.getUTCDate()).slice(-2) + "/" + d.getUTCFullYear() + " " + ("0" + d.getUTCHours()).slice(-2) + ":" + ("0" + d.getUTCMinutes()).slice(-2) + ":" + ("0" + d.getUTCSeconds()).slice(-2);

If you don't want the time in UTC, you can simply puzzle it around to remove it.

about 4 years ago · Juan Pablo Isaza Report

0

new Date("2022-06-09T22:00:00Z")
about 4 years ago · Juan Pablo Isaza Report

0

You can use angular pipe date

<span>{{ str | date: 'mm/dd/yyyy h:mm:ss' }}</span>

StackBlitz

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!