JavaScript获取当前日期
具体实现如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JavaScript获取当前日期</title>
<script type="text/javascript">
/**
*获取日期
*
**/
function findDate()
{
//实例化一个对象date
var date = new Date();
//获取年份
var year = date.getFullYear();
//获取月份
var month = date.getMonth() + 1;
//获取日子
var day = date.getDate();
//拼接日期
var thisDate = year + "-" + (month<10 ? "0" + month : month) + "-" + (day<10 ? "0" + day : day);
//打印日期
alert("当前日期:" + thisDate);
}
</script>
</head>
<body>
<input type="button" value="获取日期" οnclick="findDate()"/>
</body>
</html>
实例结果