欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Vue.js 時間轉(zhuǎn)換代碼及時間戳轉(zhuǎn)時間字符串

 更新時間:2018年10月16日 11:43:29   作者:tangong0439  
這篇文章主要介紹了Vue.js 時間轉(zhuǎn)換代碼及時間戳轉(zhuǎn)時間字符串,需要的朋友可以參考下

Date.prototype.format = function(format){
 var o = {
 "M+" : this.getMonth()+1, //month
 "d+" : this.getDate(), //day
 "h+" : this.getHours(), //hour
 "m+" : this.getMinutes(), //minute
 "s+" : this.getSeconds(), //second
 "q+" : Math.floor((this.getMonth()+3)/3), //quarter
 "S" : this.getMilliseconds() //millisecond
 }
if(/(y+)/i.test(format)) {
 format = format.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
 }
for(var k in o) {
 if(new RegExp("("+ k +")").test(format)) {
 format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
 }
 }
 return format;
 }
//使用方法
var now = new Date();
 var nowStr = now.format("yyyy-MM-dd hh:mm:ss");
 //使用方法2:
 var testDate = new Date();
 var testStr = testDate.format("YYYY年MM月dd日hh小時mm分ss秒");
alert(testStr);
 //示例:
alert(new Date().format("yyyy年MM月dd日"));
alert(new Date().format("MM/dd/yyyy"));
 alert(new Date().format("yyyyMMdd"));
 alert(new Date().format("yyyy-MM-dd hh:mm:ss"));

代碼:

// 格式化formatter中顯示的時間格式
// Date.prototype.Format = function(fmt) {
 // const o = {
// 'M+': this.getMonth() + 1, // 月份
// 'd+': this.getDate(), // 日
// 'h+': this.getHours(), // 小時
// 'm+': this.getMinutes(), // 分
// 's+': this.getSeconds(), // 秒
// 'q+': Math.floor((this.getMonth() + 3) / 3), // 季度
// 'S': this.getMilliseconds(), // 毫秒
// };
 // if (/(y+)/.test(fmt)) { fmt = fmt.replace(RegExp.$1, (`${this.getFullYear()}`).substr(4 - RegExp.$1.length)); }
 // for (const k in o) {
// if (new RegExp(`(${k})`).test(fmt)) { fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : ((`00${o[k]}`).substr((`${o[k]}`).length))); }
// }
// return fmt;
 // };

應用:

1、 2018-10-10 轉(zhuǎn) 年月日

// new Date(this.envPlanList[i].starttime.slice(0, 4),
// this.envPlanList[i].starttime.slice(5, 7),
// this.envPlanList[i].starttime.slice(8, 10)),
// new Date(this.envPlanList[i].endtime.slice(0, 4),
// this.envPlanList[i].endtime.slice(5, 7),
// this.envPlanList[i].endtime.slice(8, 10)),

2、 年月日 轉(zhuǎn) 2018-10-10

formatter(params) {
return `${params.name}: ${new Date(params.value[1]).Format('yyyy/MM/dd')} - - ${new Date(params.value[2]).Format('yyyy/MM/dd')} -- ${params.value[3]}`;
// return `${params.name}: ${params.value[1]} -- ${params.value[2]} -- ${params.value[3]}`;
},

下面看下vue.js時間戳轉(zhuǎn)時間字符串

formartDate(param) {
 let date = new Date(param);
 Y = date.getFullYear() + '-';
 M = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) + '-' : date.getMonth() + 1 + '-';
 D = date.getDate() < 10 ? '0' + date.getDate() + ' ' : date.getDate() + ' ';
 h = date.getHours() < 10 ? '0' + date.getHours() + ':' : date.getHours() + ':';
 m = date.getMinutes() < 10 ? '0' + date.getMinutes() + ':' : date.getMinutes() + ':';
 s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
 return Y + M + D + h + m + s;
}

總結(jié)

以上所述是小編給大家介紹的Vue.js 時間轉(zhuǎn)換代碼及時間戳轉(zhuǎn)時間字符串,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關文章

  • vue彈窗組件使用方法

    vue彈窗組件使用方法

    彈窗是一個項目必備的復用利器,這篇文章主要介紹了vue彈窗組件的使用方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-04-04
  • Vue3中reactive函數(shù)toRef函數(shù)ref函數(shù)簡介

    Vue3中reactive函數(shù)toRef函數(shù)ref函數(shù)簡介

    這篇文章主要介紹了Vue3中的三種函數(shù),分別對reactive函數(shù)toRef函數(shù)以及ref函數(shù)原理及使用作了簡單介紹,有需要的朋友可以借鑒參考下
    2021-09-09
  • Vue?socket.io模塊實現(xiàn)聊天室流程詳解

    Vue?socket.io模塊實現(xiàn)聊天室流程詳解

    vue-socket.io其實是在socket.io-client(在瀏覽器和服務器之間實現(xiàn)實時、雙向和基于事件的通信)基礎上做了一層封裝,將socket掛載到vue實例上,同時可使用sockets對象輕松實現(xiàn)組件化的事件監(jiān)聽,在vue項目中使用起來更方便
    2022-12-12
  • Vue3中使用Pinia的方法詳細介紹

    Vue3中使用Pinia的方法詳細介紹

    這篇文章主要給大家介紹了關于Vue3中使用Pinia的相關資料,pinia是一個用于vue的狀態(tài)管理庫,類似于vuex,是vue的另一種狀態(tài)管理工具,文中介紹的非常詳細,需要的朋友可以參考下
    2024-01-01
  • Vue最新防抖方案(必看篇)

    Vue最新防抖方案(必看篇)

    今天小編就為大家分享一篇Vue最新防抖方案(必看篇),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-10-10
  • vue項目接口域名動態(tài)獲取操作

    vue項目接口域名動態(tài)獲取操作

    這篇文章主要介紹了vue項目接口域名動態(tài)獲取操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-08-08
  • Vue+axios實現(xiàn)統(tǒng)一接口管理的方法

    Vue+axios實現(xiàn)統(tǒng)一接口管理的方法

    這篇文章主要介紹了Vue+axios實現(xiàn)統(tǒng)一接口管理的方法,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下
    2018-07-07
  • Vite內(nèi)網(wǎng)ip訪問2種配置方式

    Vite內(nèi)網(wǎng)ip訪問2種配置方式

    這篇文章主要給大家介紹了關于Vite內(nèi)網(wǎng)ip訪問的2種配置方式,文中通過實例代碼介紹的非常詳細,對大家學習或者使用Vite具有一定的參考學習價值,需要的朋友可以參考下
    2023-07-07
  • Vue+Typescript中在Vue上掛載axios使用時報錯問題

    Vue+Typescript中在Vue上掛載axios使用時報錯問題

    這篇文章主要介紹了Vue+Typescript中在Vue上掛載axios使用時報錯問題,本文給大家介紹的非常詳細,具有一定的參考借鑒價值 ,需要的朋友可以參考下
    2019-08-08
  • Vue3?使用Element?Plus表格單選帶checkbox功能

    Vue3?使用Element?Plus表格單選帶checkbox功能

    這篇文章主要介紹了Vue3?使用Element?Plus表格單選帶checkbox,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友參考下吧
    2023-11-11

最新評論