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

95
Views
Filter date time with substring and date object

I have this string 2022-02-25 06:09 AM. How do I use return just 06:09 AM (without seconds)?

I tried two ways. One way is to convert the string into Date object and then use toLocaleTimeString. But the output is 6:09:00 AM which includes the second. Here is my code.

getMyTime(lastUpdate) { 
    let d = new Date(lastUpdate);
    return d.toLocaleTimeString();
},

  

The other way is I used substring which returns 25 06:09 AM. Not sure why it get 25. Here is my code.

getMyTime(lastUpdate) { 
    return lastUpdate.substring(19,8);        
},
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Use options like this:

getMyTime(lastUpdate) { 
    var options = { 
      hour12: true, // false if you want hour without AM or PM (24 format)
      hour: '2-digit',
      minute: '2-digit'
    };

    let d = new Date(lastUpdate);
    return d.toLocaleTimeString("en-GB", options);
}
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!