js的Date 和 Math对象

Date

// Date 对象
// 创建
// 使用Date()函数
console.log(Date())
console.log(typeof Date())  // string

// 使用对象
console.log(new Date())
console.log(typeof new Date())  // object
// 使用字符串
console.log(new Date('2019/10'))
// 使用参数
    // 参数为 年 月 日 时 分 秒 毫秒
console.log(new Date(2019,1,1,1,1,1,1))
// 使用数字 时间戳
console.log(Date.prototype)

//Get 时间
let date: Date = new Date()
// getTime() 获取时间戳
console.log(date.getTime())
// getFullYear() 获取年
console.log(date.getFullYear())
// getMonth() 获取月 tips: 为实际月 -1
console.log(date.getMonth())
// 获取日 getDate()
console.log(date.getDate())
// 获取星期 getDay()
console.log(date.getDay())
// 获取小时 getHours
console.log(date.getHours())
// 获取分钟 getMinutes
console.log(date.getMinutes())
// 获取秒 getSeconds
console.log(date.getSeconds())
// 获取毫秒 getMinllseconds
console.log(date.getMilliseconds())

// date之间 运算得到的是两个对象之间相差的毫秒

Math 对象

// Math 对象
// 四舍五入 Math.round()
console.log(Math.round(4.55))   // 5

// 像上取整 Math.ceil()
console.log(Math.ceil(4.1)) //5

// 向下取整 Math.florr()
console.log(Math.floor(3.9))    // 3

// 绝对值 Math.abs
console.log(Math.abs(-1))   // 1

// 随机数 Math.random() 0-1之间
console.log(Math.ceil(Math.random() * 10))  // 生成 1-10的随机数
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值