<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 &#
时间戳的基本操作
最新推荐文章于 2024-06-27 19:52:56 发布
本文介绍了JavaScript中处理时间戳的基本操作,包括从时间戳转换为日期对象,以及如何获取当前时间的时间戳。通过实例展示了Chrome浏览器下的运行效果,对前端开发者进行时间处理时有所帮助。
摘要由CSDN通过智能技术生成