Vue获取当前系统日期(年月日)的示例代码
作者:怯桦
发中会有要获取当前日期的需求,有的是获取到当前月份,有的是精确到分秒,在 Vue 开发中,获取当前时间是一项常见的需求,本文将深入探讨Vue获取当前系统日期(年月日),帮助您更好地利用当前时间,需要的朋友可以参考下
一、首先把下列方法复制到前端代码中去
/**
* 查询当天日期
*/
getNowDate() {
const timeOne = new Date()
const year = timeOne.getFullYear()
let month = timeOne.getMonth() + 1
let day = timeOne.getDate()
month = month < 10 ? '0' + month : month
day = day < 10 ? '0' + day : day
const NOW_MONTHS_AGO = `${year}-${month}-${day}`
return NOW_MONTHS_AGO
}
二、然后在用其他的方法调用它(以下是实例)
init() {
this.startTime = this.getNowDate() + ' ' + '00:00:00', //结果: 当前日期0点
this.endTime = this.getNowDate() + ' ' + '23:59:59' //结果: 当前日期最后一秒
}
以上就是Vue获取当前系统日期(年月日)的示例代码的详细内容,更多关于Vue获取当前系统日期的资料请关注脚本之家其它相关文章!
