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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:55:29+00:00 2026-05-14T05:55:29+00:00

In javascript you can create a Date object from a string, like var mydate

  • 0

In javascript you can create a Date object from a string, like

var mydate = new Date('2008/05/10 12:08:20');
console.log(mydate); //=> Sat May 10 2008 12:08:20 GMT+0200

Now try this using milliseconds in the string

var mydate = new Date('2008/05/10 12:08:20:551'); // or '2008/05/10 12:08:20.551'
console.log(mydate); //=> NaN

Just out of curiosity: why is this?

EDIT: thanks for your answers, which all offer sufficient explanation. Maybe in some future there will be support for use of milliseconds in date strings. Untill then I cooked up this, which may be of use to somebody:

function dateFromStringWithMilliSeconds(datestr){
    var dat = datestr.split(' ')
        ,timepart = dat[1].split(/:|\./)
        ,datestr = dat[0]+' '+timepart.slice(0,3).join(':')
        ,ms = timepart[timepart.length-1] || 0
        ,date;
    date = new Date(datestr);
    date.setMilliseconds(ms);
    return 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-14T05:55:30+00:00Added an answer on May 14, 2026 at 5:55 am

    dateString

    String value representing a date. The string should be in a format recognized by the parse method (IETF-compliant RFC 1123 timestamps).

    This format doesn’t seem to accommodate milliseconds in the date… It may be best to just define the date without ms and then call setMilliseconds() afterwards.

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

Sidebar

Related Questions

I would like to create a valid JavaScript Date object from the following string
Possible Duplicate: Create shortcut to console.log() In javascript we can easy assign functions to
I create a new Date in javascript and provide it the string value of
Can I create something like an Internet Explorer accelerator using JavaScript on the client-side?
How can I create a hash table object in JavaSript and use a date
Can I create a javascript variable and increment that variable when I press a
How can I create an environment in client-side javascript where any code related to
How can I create an update function in javascript/jquery? An update function is a
Can I create an event so I can execute some javascript whenever an element
How can i create a cookie by using javascript just for end of the

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.