javascript - How to convert date in format "YYYY-MM-DD hh:mm:ss" to UNIX timestamp -
javascript - How to convert date in format "YYYY-MM-DD hh:mm:ss" to UNIX timestamp -
how can convert time in format "yyyy-mm-dd hh:mm:ss" (e.g. "2011-07-15 13:18:52"
) unix timestamp?
i tried piece of javascript code:
date = new date("2011-07-15").gettime() / 1000 alert(date)
and works, results in nan
when add together time('2011-07-15 13:18:52') input.
var match = '2011-07-15 13:18:52'.match(/^(\d+)-(\d+)-(\d+) (\d+)\:(\d+)\:(\d+)$/) var date = new date(match[1], match[2] - 1, match[3], match[4], match[5], match[6]) // big gotcha -------------------------^^^ // month must between 0 , 11, not 1 , 12 console.log(date); console.log(date.gettime() / 1000);
javascript datetime timestamp unix-timestamp
Comments
Post a Comment