Fri Oct 31 18:00:00 UTC+0800 2008 转换 2008-10-31
function Todate(num) { //Fri Oct 31 18:00:00 UTC+0800 2008 num = num + ""; var date = ""; var month = new Array(); month["Jan"] = 1; month["Feb"] = 2; month["Mar"] = 3; month["Apr"] = 4; month["May"] = 5; month["Jan"] = 6; month["Jul"] = 7; month["Aug"] = 8; month["Sep"] = 9; month["Oct"] = 10; month["Nov"] = 11; month["Dec"] = 12; var week = new Array(); week["Mon"] = "一"; week["Tue"] = "二"; week["Wed"] = "三"; week["Thu"] = "四"; week["Fri"] = "五"; week["Sat"] = "六"; week["Sun"] = "日"; str = num.split(" "); date = str[5] + "-"; date = date + month[str[1]] + "-" + str[2]; return date; }
将时间戳处理成标准格式
function time_deal(time_stamp){ var year = time_stamp.substring(0,4); var month = time_stamp.substring(4,6); var day = time_stamp.substring(6,8); var new_time = year+"-"+month+"-"+day; return new_time; }
计算两个日期相差多少天
/** * 计算两个日期相差多少天 * @param strDateStart * @param strDateEnd * @returns */ function getDays(strDateStart,strDateEnd){ var strSeparator = "-"; //日期分隔符 var oDate1; var oDate2; var iDays; oDate1= strDateStart.split(strSeparator); oDate2= strDateEnd.split(strSeparator); var strDateS = new Date(oDate1[0], oDate1[1]-1, oDate1[2]); var strDateE = new Date(oDate2[0], oDate2[1]-1, oDate2[2]); iDays = parseInt(Math.abs(strDateS - strDateE ) / 1000 / 60 / 60 /24)//把相差的毫秒数转换为天数 return iDays ; }
获取当前时间
/** * 获取当前时间 */ function getNowFormatDate() { var date = new Date(); var seperator1 = "-"; var seperator2 = ":"; var month = date.getMonth() + 1; var strDate = date.getDate(); if (month >= 1 && month <= 9) { month = "0" + month; } if (strDate >= 0 && strDate <= 9) { strDate = "0" + strDate; } var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate; // + " " + date.getHours() + seperator2 + date.getMinutes() // + seperator2 + date.getSeconds(); return currentdate; }
时间: 2024-10-04 10:11:15