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

Ask A Question

Stats

  • Questions 516k
  • Answers 516k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You should use NSCalendar instead then. It allows you to… May 16, 2026 at 6:42 pm
  • Editorial Team
    Editorial Team added an answer Unless the database specifically supports it, polling is the only… May 16, 2026 at 6:42 pm
  • Editorial Team
    Editorial Team added an answer I'm not too sure about the various forms of units,… May 16, 2026 at 6:42 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have javascript date object which gives me a date string in this format,
How can I convert a string to a date time object in javascript by
What is a culture-invariant way of constructing a string such that the Javascript Date()
Assuming a 32-bit OS/Browser, could a Date object created in JavaScript rollover to 1970
I noticed that JavaScript's new Date() function is very smart in accepting dates in
I have a page that displays data from an object. I'm loading the object
I would like to add links on every date in my calendar. For example,
I have this compare validator: <asp:CompareValidator ID=cpvBirthDate Type=Date ControlToValidate=txtBirthDate Operator=DataTypeCheck runat=server ErrorMessage=Please enter a
I'm completely new to JQuery and MVC. I'm working on a pet project that
What I want to do is make a script on the server read a

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.