Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1027289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:13:07+00:00 2026-05-16T12:13:07+00:00

How do I format a Javascript Date object as a string? (Preferably in the

  • 0

How do I format a Javascript Date object as a string? (Preferably in the format: 10-Aug-2010)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T12:13:08+00:00Added an answer on May 16, 2026 at 12:13 pm

    For custom-delimited date formats, you have to pull out the date (or time)
    components from a DateTimeFormat object (which is part of the
    ECMAScript Internationalization API), and then manually create a string
    with the delimiters you want.

    To do this, you can use DateTimeFormat#formatToParts. You could
    destructure the array, but that is not ideal, as the array output depends on the
    locale:

    { // example 1
       let formatter = new Intl.DateTimeFormat('en');
       let example = formatter.formatToParts();
       console.log(example);
    }
    { // example 2
       let formatter = new Intl.DateTimeFormat('hi');
       let example = formatter.formatToParts();
       console.log(example);
    }

    Better would be to map a format array to resultant strings:

    function join(date, options, separator) {
       function format(option) {
          let formatter = new Intl.DateTimeFormat('en', option);
          return formatter.format(date);
       }
       return options.map(format).join(separator);
    }
    
    let options = [{day: 'numeric'}, {month: 'short'}, {year: 'numeric'}];
    let joined = join(new Date, options, '-');
    console.log(joined);

    You can also pull out the parts of a DateTimeFormat one-by-one using
    DateTimeFormat#format, but note that when using this method, as of March
    2020, there is a bug in the ECMAScript implementation when it comes to
    leading zeros on minutes and seconds (this bug is circumvented by the approach
    above).

    let date = new Date(2010, 7, 5);
    let year = new Intl.DateTimeFormat('en', { year: 'numeric' }).format(date);
    let month = new Intl.DateTimeFormat('en', { month: 'short' }).format(date);
    let day = new Intl.DateTimeFormat('en', { day: '2-digit' }).format(date);
    console.log(`${day}-${month}-${year}`);

    When working with dates and times, it is usually worth using a library (eg. luxon, date-fns, moment.js is not recommended for new projects) because of the many hidden complexities of the field.

    Note that the ECMAScript Internationalization API, used in the solutions above
    is not supported in IE10 (0.03% global browser market share in Feb
    2020).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have javascript date object which gives me a date string in this format,
I have a date string that looks like the following javascript format. I want
How to parse a string into a date object at JavaScript (without using any
How can I convert a string to a Date object in JavaScript? var st
How can I convert a string to a date time object in javascript by
Has someone validated date of this format Feb 9, 2010 12:07 PM in javascript
I'm trying to convert date formats in javascript. I get a string from a
I have a date in this format: dd.mm.yyyy When I instantiate a JavaScript date
Assuming a 32-bit OS/Browser, could a Date object created in JavaScript rollover to 1970
how to display a date as 2/25/2007 format in javascript, if i have date

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.