日期时间对象

<!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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值