web练习 显示当前时间

<!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>显示当前时间</title>
</head>
<script type="text/javascript">
 function showDate()
 {
var d=new Date();
alert(d.getFullYear()+"年"+(d.getMonth()+1)+ "月"+d.getDate()+"日"); 
 }
</script>
<body>
<input type="button" value="显示当前日期" onclick="showDate()" />
</body>

</html>

注意月份要加一

年份四位数的好要用fullyear

猜你喜欢

转载自blog.csdn.net/qq_34223351/article/details/53200755