JavaScript TimeStamp into MilliSeconds

12,822

parse(): Returns the number of milliseconds since midnight 1 January 1970 for a given date and time string passed to it.

var milliSeconds = Date.parse('09-MAR-11 04:52:43:246000000 AM');

In your datestring please change the hour/min/etc separator to : instead of ., so JS can recognize correctly the date.

jsFiddle Demo

Javascript Date Functions

Share:
12,822
Admin
Author by

Admin

Updated on July 25, 2022

Comments

  • Admin
    Admin almost 2 years

    I have a timestamp that looks like 09-MAR-11 04.52.43.246000000 AM.

    I'm trying to convert this to a time format into MilliSeconds , Could anybody please let me know as how to achieve this ?? ( I Should do this inside JavaScript Only )

    Please advice . Thanks .

  • Lalchand
    Lalchand about 13 years
    In IE 7 am getting a script error object doesn't support this property or method "var ms=d.parse('09-MAR-11 04.52.43.246000000 AM');"
  • Admin
    Admin about 13 years
    I tried this way , as you mentioned , i got NAN <html> <head> <script type="text/javascript"> function Call() { var ms=Date.parse('09-MAR-11 04:52:43:246000000 AM'); alert(ms); } </script> </head> <body onload="Call()"> </body> </html> I got NAN . Please tell me if i am missing something here
  • Admin
    Admin about 13 years
    I am getting NAN , Do i need to include any js file for this to work ?? Please advice , Thanks .
  • kapa
    kapa about 13 years
    I have only tested this on Google Chrome. Please try out my jsFiddle Demo in your browser. The range of date formats that are recognized might differ between browsers.