javascript获取当前日期和时间


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));


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM