Rumah >hujung hadapan web >tutorial js >javascript中日期转换成时间戳的小例子_javascript技巧
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;
}