0

I want to change my datetime : "2015-02-16 11:03:19.000000" into unix timestamp using javascript. I have tried the below code but its not wokring:-

var d = new Date("2015-02-16 11:03:19.000000");
document.write(d.getTime() + " milliseconds since 1970/01/01");
thefourtheye
  • 233,700
  • 52
  • 457
  • 497
user123456
  • 95
  • 2
  • 15

2 Answers2

0

try using alert for you to see

var d = new Date("2015-02-16 11:03:19.000000");
alert(d.getTime() + " milliseconds since 1970/01/01")

your code is working

and look on this

convert date to timestamp in javascript?

How do you get a timestamp in JavaScript?

Community
  • 1
  • 1
Oli Soproni B.
  • 2,774
  • 3
  • 22
  • 47
  • i have used alert too. error i am getting is:- NaN milliseconds since 1970/01/01 – user123456 Feb 26 '15 at 07:06
  • 1
    you can copy that code and paste in the the console developer tools of your browser and it will make the alert. try.. what browser are you using? it prints 1424055799000 milliseconds since 1970/01/01 – Oli Soproni B. Feb 26 '15 at 07:10
0

because your dateString style cannot be recognized by Date() Object. I have tried your code in Chrome, IE and Firefox. it works in Chrome, but not in Firefox and IE. so I recommend you try the method below.

Date() Object accepts four kinds of input.

  1. new Date();
  2. new Date(value);
  3. new Date(dateString);
  4. new Date(year, month[, day[, hour[, minutes[, seconds[, milliseconds]]]]]);

if you choose dateString, you should enter string like "2015-02-16" or "2015-02-16T11:03:19" (date and time) can be passed and parsed. The UTC time zone is used to interpret arguments in ISO 8601 format that do not contain time zone information (note that ECMAScript ed 6 draft specifies that date time strings without a time zone are to be treated as local, not UTC).

and here is the relevant documention:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date

ylsun
  • 31
  • 4