Option 1
You can initialize a Date object and call getTime() to get it in Unix form. It comes out in milliseconds so you'll need to divide by 1000 to get it in seconds.
(new Date("2016/06/06 21:03:55").getTime()/1000)
It may have decimal bits so wrapping it in Math.round
would clean that.
Math.round(new Date("2016/06/06 21:03:55").getTime()/1000)
Demo: https://jsfiddle.net/nanilab/0jpxu30z/
Option 2
The Date.parse()
method parses a string representation of a date, and returns the number of milliseconds since January 1, 1970, 00:00:00 UTC or NaN if the string is unrecognized or, in some cases, contains illegal date values (e.g. 2015-02-31).
var input = "2016-06-06 21:03:55";
input = input.split(" - ").map(function (date){
return Date.parse(date+"-0500")/1000;
}).join(" - ");
Demo: https://jsfiddle.net/nanilab/cweq2q0q/
new Date(from)
would get you a date object, and the difference would be justdate1.getHours() - date2.getHours()
without an entire library to do it for you. – Aegis