日期格式化方法 日期/时间组件方法(js原生)

日期格式化方法 日期/时间组件方法(js原生)

	const time = new Date()
			console.log(time) //Fri Nov 20 2020 21:17:02 GMT+0800 (中国标准时间)
			// 日期格式化方法
			console.log(time.toDateString()) //Fri Nov 20 2020    显示日期中的周几,月,日,年
			console.log(time.toTimeString()) //21:19:24 GMT+0800 (中国标准时间)   显示日期中的时,分和时区
			console.log(time.toLocaleDateString()) // 2020/11/20  显示日期中的周几,月,日,年
			console.log(time.toLocaleTimeString()) // 下午9:21:24 显示日期中的时,分和时区
			console.log(time.toUTCString()) //Fri, 20 Nov 2020 13:22:00 GMT 显示完整的utc日期
			
			// 日期/时间组件方法
			console.log(time.getTime())  //返回日期的毫秒数
			console.log(time.setTime(432432324234)) //设置日期毫秒数表示
			console.log(time.getFullYear()) // 返回4位数年数
			console.log(time.getUTCFullYear()) // 返回utc日期的4位数年
			console.log(time.setFullYear(2012))  //设置日期的年 (year必须是4位数) 返回的时毫秒
			console.log(time.setUTCFullYear(2021)) //设置UTC日期的年 (year必须是4位数) 返回的时毫秒
			console.log(time.getMonth()) // 返回日期的月 (0 表示1月,11表示12月)
			console.log(time.getUTCMonth()) //返回UTC日期的月 (0 表示1月,11表示12月)
			console.log(time.getDate()) //返回日期中的日(1-31)
			console.log(time.getDay()) // 返回日期中表示周几的数值
			console.log(time.getHours()) //返回日期中的时 (0-23)
			console.log(time.getSeconds()) //返回日期中的秒
			console.log(time.getMinutes()) //返回日期中的分
			console.log(time.getMilliseconds()) //返回日期的毫秒
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值