//转换为UNIX时间戳
function strtotimestamp(datestr)
{
var new_str = datestr.replace(/:/g,"-");
new_str = new_str.replace(/ /g,"-");
var arr = new_str.split("-");
var datum = new Date(Date.UTC(arr[0],arr[1]-1,arr[2],arr[3]-8,arr[4],arr[5]));
return (datum.getTime()/1000); //为PHP所用
}
//UNIX时间戳转换为字符串
function timestamptostr(timestamp) {
d = new Date(timestamp.getTime());
var jstimestamp = (d.getFullYear())+"-"+(d.getMonth()+1)+"-"+(d.getDate())+" "+(d.getHours())+":"+(d.getMinutes())+":"+(d.getSeconds());
return jstimestamp;
}
javascript timestamp 和PHP 时间戳 差 8个小时
strtotimestamp("2010-01-01 08:00:00"); //PHP输出 2010-01-01 00:00:00
strtotimestamp("2010-01-11 23:59:59")+(8*60*60); //PHP输出 2010-01-11 23:59:59