介绍
这篇文章主要介绍了如何在Vue。js中将时间转换成时间戳,此处通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考价值,需要的朋友可以参考下:
为什么要使用Vue
Vue是一款友好的,多用途且高性能的JavaScript框架,使用Vue可以创建可维护性和可测试性更强的代码库,Vue允许可以将一个网页分割成可复用的组件,每个组件都包含属于自己的HTML, CSS, JavaScript,以用来渲染网页中相应的地方,所以越来越多的前端开发者使用Vue。
Date.prototype.format =,函数(格式){ ,var 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(),//毫秒 ,} 如果(/(y +)/信息(格式),{=,,format  format.replace (RegExp, 1美元,(this.getFullYear () +““) .substr(4,安康;RegExp。1.美元长度)); ,} (var k o拷贝),{ ,如果(new 正则表达式(“(“+,k +“)“) test(格式),{=,,format  format.replace (RegExp。1美元,RegExp。1.美元==1,长度?,o [k],:, (“00”; +, o [k]) .substr ((““+, o [k]) . length)); ,} ,} ,return 格式; ,}//使用方法 var 你=,new 日期(); ,var nowStr =, now.format (“yyyy-MM-dd  hh: mm: ss"); ,//使用方法2: ,var testDate =, new 日期(); ,var testStr =, testDate.format (“YYYY年MM月dd日hh小时MM分党卫军秒“); 警报(testStr); ,//示例: 警报(new 日期().format (“yyyy年MM月dd日“)); 警报(new 日期().format (“MM/dd/yyyy")); ,警报(new 日期().format (“yyyyMMdd")); ,警报(new 日期().format (“yyyy-MM-dd  hh: mm: ss"));
代码:
//,格式化formatter中显示的时间格式=//,Date.prototype.Format 函数(fmt), { ,//const o =, {//,& # 39;M + & # 39;:, this.getMonth(), +, 1,,//,月份//,& # 39;d + & # 39;:, this.getDate(),,//日//,& # 39;h + & # 39;:, this.getHours(),,//,小时//,& # 39;m + & # 39;:, this.getMinutes(),,//分//,& # 39;s + & # 39;:, this.getSeconds(),,//秒//,& # 39;q + & # 39;:, Math.floor ((this.getMonth(), +, 3),/, 3),,//,季度//,& # 39;& # 39;:,this.getMilliseconds(),,//,毫秒//,}; ,//if (/(y +)/test (fmt)), {, fmt =, fmt.replace (RegExp, 1美元,(“$ {this.getFullYear ()}”) .substr(4,安康;RegExp。长度)1.美元);,} ,//for (const k 拷贝o), {//,if (new 正则表达式(($ {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 日期(this.envPlanList[我].starttime.slice (0, 4),//,this.envPlanList[我].starttime.slice (5, 7),//,this.envPlanList[我].starttime.slice (8, 10)),//,new 日期(this.envPlanList[我].endtime.slice (0, 4),//,this.envPlanList[我].endtime.slice (5, 7),//,this.envPlanList[我].endtime.slice (8, 10)),
2年月日转2018-10-10
格式化程序(params), { return ,“$ {params.name}: $ {new 日期(params.value [1]) .Format (& # 39; yyyy/MM/dd # 39;)},安康;作用;$ {new 日期(params.value [2]) .Format (& # 39; yyyy/MM/dd # 39;)},,, $ {params.value [3]} ';//,return ,“$ {params.name}: $ {params.value [1]},,, $ {params.value [2]},,, $ {params.value [3]} '; },
<>强下面看下vue。js时间戳转时间字符串强>
formartDate(参数),{ ,let date =, new 日期(参数);=,,Y  date.getFullYear (), +, & # 39; & # 39;;=,,M  date.getMonth (), +, 1, & lt;, 10, ?, & # 39; 0 & # 39;, +, (date.getMonth (), +, - 1), +, & # 39; & # 39;,:, date.getMonth (), +, - 1, +, & # 39; & # 39;;=,,D  date.getDate (), & lt;, 10, ?, & # 39; 0 & # 39;, +, date.getDate (), +, & # 39;, & # 39;,:, date.getDate (), +, & # 39;, & # 39;;=,,h  date.getHours (), & lt;, 10, ?, & # 39; 0 & # 39;, +, date.getHours (), +, & # 39;: & # 39;,:, date.getHours (), +, & # 39;: & # 39;;=,,m  date.getMinutes (), & lt;, 10, ?, & # 39; 0 & # 39;, +, date.getMinutes (), +, & # 39;: & # 39;,:, date.getMinutes (), +, & # 39;: & # 39;; null null null如何在Vue.js中将时间转换成时间戳