获取当前时间信息
至诚网络2019-03-27 11:25:05265<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>获取当前时间信息</title>
</head>
<body>
<script type="text/javascript">
//获取当前时间
var myday = new Date();
// document.write(myday);
// Wed Mar 27 2019 10:29:43 GMT+0800 (中国标准时间)
// 星期 月份 日 年份 时间
//获取年份 getFullYear() 前提是要先获取时间
document.write('现在是'+myday.getFullYear()+'年');
//获取月份 getMonth() 0代表是1
// document.write(myday.getMonth()+'月'+'<br>');
var month = new Array(12);
month[0] = '1月'
month[1] = '2月'
month[2] = '3月'
month[3] = '4月'
month[4] = '5月'
month[5] = '6月'
month[6] = '7月'
month[7] = '8月'
month[8] = '9月'
month[9] = '10月'
month[10] = '11月'
month[11] = '12月'
document.write(month[myday.getMonth()]);
// 获取日期 getDate()返回值是0~31之间的整数
document.write(myday.getDate()+'日');
// 获取星期 getDay() 0代表的是周日 6代表的是周六 (返回值是0~6之间的一个整数)
// document.write(myday.getDay());
var day = new Array(7);
day[0] = '星期天'
day[1] = '星期一'
day[2] = '星期二'
day[3] = '星期三'
day[4] = '星期四'
day[5] = '星期五'
day[6] = '星期六'
document.write(day[myday.getDay()]);
//获取小时 getHours() 0~23
document.write(myday.getHours()+'时');
// 获取分钟 getMinutes() 0~59
document.write(myday.getMinutes()+'分');
//获取秒针 getSeconds() 0~59
document.write(myday.getSeconds()+'秒');
</script>
</body>
</html>