布尔,日期,数值对象

布尔对象

// 使用构造函数方式创建boolean对象
    // Boolean 作用创建布尔对象,将其他类型数据转化为布尔类型
    var bool = new Boolean(true);
    console.log(bool)
    // constructor 指向对象的构造函数
    console.log(bool.constructor)
    // 将其他类型数据转化为布尔类型,并同时创建一个布尔对象
    var bool1 = new Bloolean('')
    console.log(bool1.constructor)

日期对象

// 日期对象作用:获取当前时间
        // 实例化日期对象  记录当前时间
        // 日期对象.api()
        var date = new Date()
        console.log(date)
        console.dir(date)
        console.dir(date.getFullYear()); //年
        var data = date.getDate() + 1;  // 月  0-11
        // 返回星期几 0-6
        var day = date.getDay(); // 日
        var mouce = date.getMonth(); // 星期
        var hour = date.getHours();  // 时
        var minute = date.getMinutes();  // 分
        var second = date.getSeconds();  // 秒
        var ms = date.getMilliseconds(); // 毫秒
        // 时间戳是时间的唯一标识。唯一一个可以代表当前时间的表示。
        var time = date.getTime(); // 时间戳  具有唯一性,

        switch (day) {
            case 1 : 
            day = '一';
            break;
            case 2 : 
            day = '二';
            break;
            case 3 : 
            day = '三';
            break;
            case 4 : 
            day = '四';
            break;
            case 5 : 
            day = '五';
            break;
            case 6 : 
            day = '六';
            break;
            case 0 : 
            day = '日';
            break;  
        }
        // 展示当前时间到秒
        console.log(date.getFullYear() 
        + '-' + mouce 
        + '-' + data 
        + ' ' + hour 
        + ':' + minute 
        + ':' + second 
        + ' 星期' + day)

数值对象

console.log(window.Math)
        var num = 4.05;
        //  Math.floor() 向下取整
        console.log(Math.floor(num)) // 2
        //  Math.ceil() 向上取整
        console.log(Math.ceil(num)); // 3
        //  Math.round() 四舍五入
        console.log(Math.round(num))  // 3
        // Math.random() 出现0-1随机小数
        console.log(Math.random())
        // 求 1 - 10 随机整数
        console.log(Math.floor((Math.random() * 10)))


        // Math.max() 返回最大值
        console.log(Math.max(1,2,54,555))
        // Math.min() 返回最小值
        console.log(Math.min(1,55,2,587))
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值