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

首頁 > 語言 > JavaScript > 正文

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

2024-05-06 15:28:42
字體:
供稿:網(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;}            
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 綦江县| 贵南县| 广东省| 嘉禾县| 安溪县| 营口市| 响水县| 南投县| 南岸区| 邯郸市| 临猗县| 镶黄旗| 宁河县| 隆回县| 阳山县| 牙克石市| 闻喜县| 巢湖市| 新昌县| 上蔡县| 当涂县| 太仆寺旗| 仁怀市| 萝北县| 石阡县| 绥德县| 呼玛县| 车致| 安远县| 晋州市| 鄂温| 乌鲁木齐市| 铜陵市| 宁安市| 房产| 双柏县| 浙江省| 肇州县| 上高县| 辉县市| 揭阳市|