js获取格式化后的当前时间
代码如下:
function getFormatDate() { var day=new Date(); var Year=0; var Month=0; var Day=0; var Hour = 0; var Minute = 0; var Second = 0; var CurrentDate=""; //初始化时间 Year = day.getFullYear(); Month = day.getMonth()+1; Day = day.getDate(); Hour = day.getHours(); Minute = day.getMinutes(); Second = day.getSeconds(); CurrentDate = CurrentDate + Year + "-"; if (Month >= 10 ){ CurrentDate = CurrentDate + Month + "-"; }else{ CurrentDate = CurrentDate + "0" + Month + "-"; } if (Day >= 10 ){ CurrentDate = CurrentDate + Day }else{ CurrentDate = CurrentDate + "0" + Day } if(Hour >=10){ CurrentDate += " "+Hour }else{ CurrentDate += " 0" + Hour } if(Minute >=10){ CurrentDate = CurrentDate + ":" + Minute }else{ CurrentDate = CurrentDate + ":0" + Minute } if(Second>=10){ CurrentDate = CurrentDate + ":" + Second; }else{ CurrentDate = CurrentDate + ":0" + Second; } return CurrentDate; }