Vue.js 时间转换代码及时间戳转时间字符串
网络编程 2021-07-04 16:46www.168986.cn编程入门
这篇文章主要介绍了Vue.js 时间转换代码及时间戳转时间字符串,需要的朋友可以参考下
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 转 年月日
// 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、 年月日 转 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]}`; },
狼蚁网站SEO优化看下vue.js时间戳转时间字符串
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; }
以上所述是长沙网络推广给大家介绍的Vue.js 时间转换代码及时间戳转时间字符串,希望对大家有所帮助,如果大家有任何疑问请给我留言,长沙网络推广会及时回复大家的。在此也非常感谢大家对狼蚁SEO网站的支持!
编程语言
- 宿迁百度关键词排名指南:实现精准营销的关键
- 四川SEO优化怎么做网络推广
- 立昂技术备案老域名收购:如何为您的业务赋能
- 安徽百度关键词seo贵不贵,一般需要多少钱
- 吉林百度快照排名怎么做电话营销
- 多伦新手做SEO怎么做
- 甘肃优化关键词排名推广怎么做论坛营销
- 沙雅SEO网站推广:提升您的在线可见性
- 四川SEO优化如何提升销售额和销售量
- 聂荣网站排名优化:提升网站可见性的全方位指
- 涞水SEO:提升地方企业在线可见性的策略
- 辽宁百度seo排名怎样做网站排名
- 临湘哪有关键词排名优化:提升网站可见度的关
- 黑龙江百度网站优化有没有优惠
- 凉城优化关键词排名推广:提升您的网络可见性
- 萝北整站优化:提升您网站流量和排名的全面指