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 8815131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:17:57+00:00 2026-06-14T04:17:57+00:00

I want to parse dates (string date format to javascript date format), but I

  • 0

I want to parse dates (string date format to javascript date format), but I have various string date format like YYYY-MM-DD, DD-MM-YYYY and 'DD/MM/YYYY' and so..

Is there any generic procedure or way to convent from these string date format to javascript date format?

  • 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-06-14T04:17:58+00:00Added an answer on June 14, 2026 at 4:17 am

    Here userFormat string could be in these format 'DD-MM-YYYY', 'YYYY-MM-DD', 'DD/MM/YYYY' etc..

    function parseDate(dateString, userFormat) {
        var delimiter, theFormat, theDate, month, date, year;
        // Set default format if userFormat is not provided
        userFormat = userFormat || 'yyyy-mm-dd';
    
        // Find custom delimiter by excluding
        // month, day and year characters
        delimiter = /[^dmy]/.exec(userFormat)[0];
    
        // Create an array with month, day and year
        // so we know the format order by index
        theFormat = userFormat.split(delimiter);
    
        //Create an array of dateString.
        theDate = dateString.split(delimiter);
        for (var i = 0, len = theDate.length; i < len; i++){
          //assigning values for date, month and year based on theFormat array.
          if (/d/.test(theFormat[i])){
            date = theDate[i];
          }
          else if (/m/.test(theFormat[i])){
            month = parseInt(theDate[i], 10) - 1;
          }
          else if (/y/.test(theFormat[i])){
            year = theDate[i];
          }
        }
        return (new Date(year, month, date));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to parse a date into my format like 02:09 AM 25/09/2012 but
I have a date string and I want to parse it to normal date
HI, I am converting String to Date format. But it returns wrong dates. for
I have a date string in format 08/1999 I want to get the first
I want to parse a date from a given string. The format of the
I have string Tue Nov 12 2010,I want to parse it in java.util.Date object.
I want to parse a date string but I fail miserably. To illustrate my
I want the date format as dd-MMM-yyyy. My code is: String v_date_str=Sun Mar 06
Is there any way to parse a string in the format HH:MM into a
I have strings with dates, and want to parse these into NSDate objects. Is

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.