23

Say, I have a date

var dt = new Date('2012-01-01');

Is there a method in Javascript to return number of milliseconds since 1970-01-01? For this particulat date it would return 1325376000000

For this purpose, there is a method "toUTC()" that runs in Chrome only. I know this because i can do that in Chrome's console. See screen attached below:

enter image description here

However, When I search about this method on the internet, I don't find it and it doesn't work in Firefox either which is very wierd and I am very confused.

Anyhow, if you know any way to get this, will be really appreciated.

Thank You

Community
  • 1
  • 1
Cute_Ninja
  • 4,742
  • 4
  • 39
  • 63

2 Answers2

6

Use the getTime function:

var dt = new Date('2012-01-01');
var time = dt.getTime();
Cameron Tinker
  • 9,634
  • 10
  • 46
  • 85
1

You can get it with:

new Date('2012-01-01').getTime();

The getTime() method returns the number of milliseconds between midnight of January 1, 1970 and the specified date.

gipinani
  • 14,038
  • 12
  • 56
  • 85