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

213
Views
Get Date in Consistent Format

I am having a function which return the date based on some condition (last 30 day).

const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
const startTime = start.toLocaleString().split(",")[0];
console.log(startTime)

In Mac OS,I am getting the output in dd/mm/yyyy format (which is the desired format).

But in Windows , I am getting the output in mm/dd/yyyy. How can I make it consistent irespective of platform. Desired format is dd/mm/yyy

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

0

Use toLocaleDateString with locale

The en-GB locale seems what you want here

I made a more useful and self-describing function

const ddmmyyyy = (d, offset) => {
  d.setTime(d.getTime() + (3600 * 1000 * 24 * offset))
  return d.toLocaleDateString('en-GB')
};

console.log(
  ddmmyyyy(new Date(), -30)
)

about 4 years ago · Juan Pablo Isaza Report

0

Use toLocaleDateString with 'en-GB'

const start = new Date();
start.setDate(start.getDate() - 30)
const startTime = start.toLocaleDateString('en-GB');
console.log(startTime)

about 4 years ago · Juan Pablo Isaza Report

0

function SetShortDateTime(d) {
  const monthList = [
    "01",
    "02",
    "03",
    "04",
    "05",
    "06",
    "07",
    "08",
    "09",
    "10",
    "11",
    "12"
  ];


  const yr = d.getFullYear();
  const mnt = monthList[d.getMonth()];
  const day = d.getDate() < 10 ? "0" + d.getDate() : d.getDate();

  return [day, mnt, yr].join("/");
}

console.log(SetShortDateTime(new Date(2021,11,9,10)))

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!