詳解vue如何獲取當(dāng)前系統(tǒng)時(shí)間
1.獲取當(dāng)前系統(tǒng)時(shí)間時(shí)分秒
// 標(biāo)準(zhǔn)時(shí)間格式轉(zhuǎn)化為年月日時(shí)分秒
export function ssDateTimeFn(timestamp) {
if (!timestamp) {
return timestamp
}
// timestamp是整數(shù),否則要parseInt轉(zhuǎn)換,不會(huì)出現(xiàn)少個(gè)0的情況
const time = new Date(timestamp)
const year = time.getFullYear()
const month = time.getMonth() + 1
const date = time.getDate()
const hours = time.getHours()
const minutes = time.getMinutes()
const seconds = time.getSeconds()
return year + '-' + add0(month) + '-' + add0(date) + ' ' + add0(hours) + ':' + add0(minutes) + ':' + add0(seconds)
}import {
ssDateTimeFn
} from '@/utils/commonss' // 公共事件引入使用ssDateTimeFn(new Date())

2.// 標(biāo)準(zhǔn)時(shí)間格式轉(zhuǎn)化為年月日時(shí)分
// 標(biāo)準(zhǔn)時(shí)間格式轉(zhuǎn)化為年月日時(shí)分
function mmDateTimeFn(timestamp) {
if (!timestamp) {
return timestamp
}
// timestamp是整數(shù),否則要parseInt轉(zhuǎn)換,不會(huì)出現(xiàn)少個(gè)0的情況
const time = new Date(timestamp)
const year = time.getFullYear()
const month = time.getMonth() + 1
const date = time.getDate()
const hours = time.getHours()
const minutes = time.getMinutes()
// const seconds = time.getSeconds()
return year + '-' + add0(month) + '-' + add0(date) + ' ' + add0(hours) + ':' + add0(minutes)
}3.年月日不帶時(shí)分
// 年月日 不帶時(shí)分
function dateFormat(timestamp) {
if (!timestamp) {
return timestamp
}
// timestamp是整數(shù),否則要parseInt轉(zhuǎn)換,不會(huì)出現(xiàn)少個(gè)0的情況
const time = new Date(timestamp)
const year = time.getFullYear()
const month = time.getMonth() + 1
const date = time.getDate()
return year + '-' + add0(month) + '-' + add0(date)
}以上就是詳解vue如何獲取當(dāng)前系統(tǒng)時(shí)間的詳細(xì)內(nèi)容,更多關(guān)于vue獲取當(dāng)前系統(tǒng)時(shí)間的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
Vue綁定class和綁定內(nèi)聯(lián)樣式的實(shí)現(xiàn)方法
本文主要介紹了Vue綁定class和綁定內(nèi)聯(lián)樣式的實(shí)現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-11-11
vue2.0使用swiper組件實(shí)現(xiàn)輪播的示例代碼
下面小編就為大家分享一篇vue2.0使用swiper組件實(shí)現(xiàn)輪播的示例代碼,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-03-03
vue-cli2.x項(xiàng)目優(yōu)化之引入本地靜態(tài)庫文件的方法
這篇文章主要介紹了vue-cli2.x項(xiàng)目優(yōu)化之引入本地靜態(tài)庫文件的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-06-06
vue backtop組件的實(shí)現(xiàn)完整代碼
這篇文章主要介紹了vue backtop組件的實(shí)現(xiàn)完整代碼,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-04-04
Vue3中element-plus全局使用Icon圖標(biāo)的過程詳解
我們在用vue開發(fā)網(wǎng)站的時(shí)候,往往圖標(biāo)是起著很重要的作,這篇文章主要給大家介紹了關(guān)于Vue3中element-plus全局使用Icon圖標(biāo)的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-01-01

