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

338
Views
How to Format Date to Complete YYYY-MM-DD-HH-MM-SS

Can you please take a look at this code and let me know how I can get the output in YYYY-MM-DD-HH-MM-SS format?

As you can see what I am getting now is 2022-04-22 which is YYYY-MM-DD

const d = new Date();
var dStr = new Date(d.getTime() - (d.getTimezoneOffset() * 60000)).toISOString().split("T")[0];

console.log(dStr);

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You can get YYYY-MM-DD-HH-MM-SS format like this:

new Date(d.getTime() - (d.getTimezoneOffset() * 60000)).toISOString().split(".")[0].replace(/[T:]/g, '-')

Explanation:

  • .split(".")[0] removes the dot near the end and everything after it.
  • .replace(/[T:]/g, '-') changes the T and the colons (:) to dashes.
about 4 years ago · Santiago Trujillo Report

0

Try this

const value = new Date().toLocaleString('sv-SE').replace(/[\s\:]/g, '-')
console.log(value)

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