js 时间格式转换

js时间格式转换

格式化时间转成时间戳

//格式化转时间戳(单位秒)
function strtotime(strtime) {
strtime = strtime.substring(0, 19);
strtime = strtime.replace(/-/g, '/');
strtime = new Date(strtime).getTime() / 1000;
return strtime;
}

时间戳转格式化时间

        //时间戳(单位秒)转格式化
function getMyDate(str) {
str = str * 1000;
var oDate = new Date(str),
oYear = oDate.getFullYear(),
oMonth = oDate.getMonth() + 1,
oDay = oDate.getDate(),
oHour = oDate.getHours(),
oMin = oDate.getMinutes(),
oSen = oDate.getSeconds(),
oTime = oYear + '-' + getzf(oMonth) + '-' + getzf(oDay) + ' ' + getzf(oHour) + ':' +
getzf(oMin) + ':00'; //最后拼接时间
return oTime;
};
上一篇:Notepad++中代码格式化插件NppAStyle


下一篇:UISearchDisplayController 阴影遮盖frame调整