时间戳的基本操作

【代码】时间戳的基本操作。
摘要由CSDN通过智能技术生成
<template>
	<view></view>
</template>

<script>
	export default {
		data() {
			return {
				number: "",
				time: ""
			}
		},
		onLoad() {

			this.number = Date.now() //获取当前时间戳,以毫秒为单位//
			this.time = new Date() //获取当前标准时间//
			console.log(this.number)
			console.log(this.time)

			//Date.now()和new Date()获取的值可以相互转换//
			console.log(Date.now(this.time))
			console.log(new Date(this.number))

			//操作一:对时间进行格式化//
			console.log(this.toFormat(this.time))

			//操作二:计算当月天数//
			console.log(this.getDays())

			//操作三:日期计算//
			//获取的时间戳以毫秒为单位,一天的毫秒数60*60*24*1000//
			let num = this.number - 60 * 60 * 24 * 1000 * 7
			//格式化当前时间的七天前//
			console.log(this.toFormat(new Date(num)))
		},
		methods: {
			//时间格式化处理//
			toFormat(date) {
				let y = date.getFullYear()
				let m = date.getMonth() + 1 //获取的值为0-11,所以需要+1//
				let d = date.getDate()
				let h &#
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值