javascript中日期转换成时间戳
/**
* 日期转化成时间戳
* 日期格式 2011-02-02 21:12:13
* time_str:日期段 2011-02-02
* fix_time:时间段 21:12:13
*/
function strtotime(time_str, fix_time) {
var time = (new Date()).getTime();
if(time_str) {//有日期段
var str = time_str.split('-');
if (3 === str.length) {
var year = parseInt(str[0]) - 0;
var month = parseInt(str[1]) - 0 - 1;//月份是从0开始的
var day = parseInt(str[2]) - 0;
if(fix_time) {//有时间段
var fix = fix_time.split(':');
if (3 === fix.length) {
var hour = parseInt(fix[0]) - 0;
var minute = parseInt(fix[1]) - 0;
var second = parseInt(fix[2]) - 0;
time = (new Date(year, month, day, hour, minute, second)).getTime();
}
} else {
time = (new Date(year, month, day)).getTime();
}
}
}
//getTime()获取的时间戳到了毫秒数
time = time / 1000;//转到到秒数
return time;
}