<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
// 日期对象 JS内置对象 ,跟时间有关系
// 1.创建日期对象 如果()里没有参数,返回的是系统当前时间
var date = new Date();
console.log(date);
// 2.如果()有参数 写字符串型 日期 年-月-日 时:分:秒
var ipt_date = new Date("2022-12-31 23:59:59");
console.log(ipt_date);
// 3.参数为0 ,返回的时间为1970年1月1日
var date1970 = new Date(0);
console.log(date1970);//
// 4.获取当前时间
var date = new Date();
// 实例化日期对象
console.log(date);//返回系统当前时间
console.log(date.getFullYear());// 获取当前日期对象的年份 4位数 2022
console.log(date.getMonth() + 1);// 获取当前日期的月份 0-11 ,比实际月份少1,所以手动+1
console.log(date.getDate());// 获取当前日期对象的具体天数 20号 1-31
console.log(date.getHours());// 获取当前时间的小时数(0-23)
console.log(date.getMinutes());// 获取当前时间分钟数 (0-59)
console.log(date.getSeconds());// 获取当前时间秒钟数 (0-59)
console.log(date.getDay());// 获取星期几(0-6) 0表示周日
/* 一月:January , 简写: Jan.
二月:February , 简写:Feb.
三月:March , 简写:Mar.
四月:April , 简写:Apr.
五月:May , 简写:May.
六月:June , 简写:June.
七月:July , 简写:July.
八月:August , 简写:Aug.
九月:September , 简写:Sep.
十月:October , 简写:Oct.
十一月:November, 简写:Nov.
十二月:December , 简写: Dec.
*/
</script>
</body>
</html>
日期时间对象
最新推荐文章于 2024-05-06 04:24:45 发布