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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:53:54+00:00 2026-05-23T18:53:54+00:00

I have a datetime string being provided to me in the following format: yyyy-MM-dd

  • 0

I have a datetime string being provided to me in the following format:

yyyy-MM-dd HH:mm:ss
2011-07-14 11:23:00

When attempting to parse it into a JavaScript date() object it fails. What is the best way to convert this into a format that JavaScript can understand?

The answers below suggest something like

var myDate = new Date('2011-07-14 11:23:00');

Which is what I was using. It appears this may be a browser issue. I’ve made a http://jsfiddle.net/czeBu/ for this. It works OK for me in Chrome. In Firefox 5.0.1 on OS X it returns Invalid Date.

  • 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-23T18:53:55+00:00Added an answer on May 23, 2026 at 6:53 pm

    The failure is up to the browser implementation’s handling of Date.parse and how they allow for date strings not conform the date standards

    ECMAScript defines a string interchange format for date-times based upon a simplification of the ISO 8601 calendar date extended format.
    The format is as follows: YYYY-MM-DDTHH:mm:ss.sssZ

    So we can force your string into this

    const getDateFromString = str => {
      const [date,time] = str.split(" ");
      // reformat string into YYYY-MM-DDTHH:mm:ss.sssZ
      str = `${date}T${time}.000Z`
      return new Date(str);
    };
    let date = getDateFromString('2011-07-14 11:23:00');
    console.log(date)

    Older answer:

    As for your format, some OSX browsers insist on the dashes being slashes.

    This works everywhere including Safari 5 and Firefox 5 on OS X.

    UPDATE: Fx Quantum (54) has no need for the replace, but Safari 11 is still not happy unless you convert as below

    var date_test = new Date("2011-07-14 11:23:00".replace(/-/g,"/"));
    console.log(date_test);
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following method: public object[] GetEventsByUser(DateTime start, DateTime end, string fullUrl) The
I have a problem while converting a string whose value is dd.mm.yyyy to DateTime
I have the following wonderfully unreliable statement: string LastsuccessfuldownloadDateTime = 04.07.2009 19:21:36 DateTime myDate
I have this object: class a { public string Application; public DateTime From, To;
So I have a flashobject which I need to pass a formatted DateTime string
I've done some simple string -> DateTime conversions before using DateTime.ParseExact(), but I have
I have this: Dim myTemp As String myTemp = System.DateTime.Now().ToString(MMMddyyyy_HHmmss) & .pdf System.IO.File.Copy(myFile, c:\
I have a huge list of datetime strings like the following ["Jun 1 2005
Not sure what's going on here. I have a DateTime object, and when I
I have a parameter string that passes date value to a stored proc cmdItemSearch.Parameters.Add(new

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.