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:
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
JavaScript Date getTime() getTime() returns the number of milliseconds since January 1, 1970 00:00:00.
now() The static Date. now() method returns the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC.
JavaScript - Date getMilliseconds() Method Javascript date getMilliseconds() method returns the milliseconds in the specified date according to local time. The value returned by getMilliseconds() is a number between 0 and 999.
getTime() The getTime() method returns the number of milliseconds since the ECMAScript epoch. You can use this method to help assign a date and time to another Date object. This method is functionally equivalent to the valueOf() method.
Use the getTime function:
var dt = new Date('2012-01-01');
var time = dt.getTime();
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With