国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > JavaScript > 正文

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

2019-11-19 12:41:31
字體:
供稿:網(wǎng)友
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小時(shí)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中顯示的時(shí)間格式// Date.prototype.Format = function(fmt) { // const o = {// 'M+': this.getMonth() + 1, // 月份// 'd+': this.getDate(), // 日// 'h+': this.getHours(), // 小時(shí)// '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; // };

應(yīng)用:

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時(shí)間戳轉(zhuǎn)時(shí)間字符串

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 時(shí)間轉(zhuǎn)換代碼及時(shí)間戳轉(zhuǎn)時(shí)間字符串,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)武林網(wǎng)網(wǎng)站的支持!

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 本溪| 罗江县| 三穗县| 宜黄县| 广丰县| 桑日县| 武威市| 丰台区| 黔东| 安新县| 黑河市| 西贡区| 南郑县| 屯门区| 通渭县| 德安县| 阳信县| 镇远县| 舒兰市| 黄石市| 鹤峰县| 石门县| 濮阳市| 沂南县| 咸宁市| 社旗县| 通辽市| 罗平县| 丹凤县| 余江县| 浙江省| 罗城| 项城市| 三江| 固原市| 社旗县| 庄河市| 武安市| 明水县| 乌海市| 金坛市|