JS千年虫解决

//将时间数字转换成指定格式的日期字符串
function getDateString(format, numberTime){

if(numberTime != undefined && numberTime != null){

var date = new Date();

date.setTime(numberTime);

localTime = date.getTime();

localOffset=date.getTimezoneOffset()*60000; //获得当地时间偏移的毫秒数

utc = localTime + localOffset; //utc即GMT时间

offset =10; //以夏威夷时间为例,东10区

hawaii = utc + (3600000*offset);

nd = new Date(hawaii);
if(format == "yyyy-MM-dd")
return getShortDateString(nd);
}

return "";
}

function getShortDateString(date) { //如:2011-07-29
var year = date.getFullYear();
var month = date.getMonth();
var day = date.getDate();
month = month + 1;
if (month < 10) month = '0' + month;
if (day < 10) day = '0' + day;
var str = year + '-' + month + '-' + day;
return str;
}

你可能感兴趣的:(javascript)