function GetDate(format) {
/**
* format=1表示获取年月日
* format=0表示获取年月日时分秒
* **/
var now = new Date();
var year = now.getFullYear();
var month = now.getMonth()+1;
var date = now.getDate();
var day = now.getDay();//得到周几
var hour = now.getHours();//得到小时
var minu = now.getMinutes();//得到分钟
var sec = now.getSeconds();//得到秒
if (format==1){
_time = year+"-"+month+"-"+date
}
else if (format==2){
_time = year+"-"+month+"-"+date+" "+hour+":"+minu+":"+sec
}
return _time
}
alert("当前日期为: " + GetDate(0));
相关文章:
- JavaScript获取系统当前日期和时间、星期几 2021-12-24
- JS获取当前日期及 js获取当前时间和一星期前的时间 2022-01-02
- Python获取当前时间(日期+时间) 2022-12-23
- js获取当前时间日期 2021-12-09
- Python获取当前时间日期 2021-11-28
- JS获取当前日期时间 2021-12-22