JS Date类型

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
// 获取当前日期对象
var date = new Date()
console.log(date) // Sat Jun 04 2022 20:04:17 GMT+0800 (中国标准时间)
// 获取时间片
console.log(date.getFullYear()) // 年
console.log(date.getMonth()) // 月
console.log(date.getDate()) // 日
console.log(date.toString()) // 字符串输出:Sat Jun 04 2022 20:04:36 GMT+0800 (中国标准时间)
console.log(date.toLocaleString()) // 2022/6/4 20:04:59

// 构建日期对象
var date2 = new Date("2012/12/12")
console.log(date2.getFullYear()) // 2012
console.log(date2.getMonth()) // 11
console.log(date2.getDate()) // 12



</script>
</head>
<body>
<h1>welcome to JS!</h1>
</body>
</html>

 

posted @   呼长喜  阅读(23)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
历史上的今天:
2018-06-04 运维常用巡检命令
点击右上角即可分享
微信分享提示