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

231
Views
JavaScript: Generate current date with custom format

I am trying to generate the current date in the Date Month, Year format. Currently I am using following code:

function currentDate() 
{
    var months = [
        'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 
        'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
    ];

    var date = new Date();
    var d = date.getDate();
    var m = date.getMonth();
    var y = date.getFullYear();

    return `${d} ${months[m]}, ${y}`;
}

Although, It's works perfectly. But, is there a shorter way to do this..?

Something like:

(new Date()).format('d M, Y')
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Unfortunately, there isnt.

But you can use libraries like luxon:

DateTime.now().toFormat('d M, Y')

Or, if you want to stay native, you can use Intl.DateTimeFormat:

new Intl.DateTimeFormat('es-US', { dateStyle: 'full' }).format(d);

However, ECMAScript currently has a proposal to improve Date class by adding Temporal global object:

Temporal.now.date().toLocaleString('es-US', {
  weekday: 'long',
});
about 4 years ago · Juan Pablo Isaza Report

0

There is no simple way to do that. Instead, you could see other alternatives.

If you are already using new Date() all over the application. I suggest dayjs. It has all the date-utilities you are looking for.

It works with new Date() object also.

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!