1. Conversion of time
默认
mounted () { this.HomePageDisplay(); var myDate = new Date(); var reg=/[\u4E00-\u9FA5]/g; this.latestS=myDate.toLocaleString().replace(/\//g,'-').replace(/:/g,'-').replace(/[ ]/g,"").replace(reg,''); console.log(this.latestS) },
I converted this.
What I want is 2017-07-05-04. .
2. Regarding the addition and subtraction of time.
1、2017-07-05-04 减去10个小时。 格式不变。。 2、 当前的小时减去10个小时。。 下面代码我写的。 给自己蠢哭了。 求指点。。
var timeData = [ myDate.getHours()-10, myDate.getHours()-9, myDate.getHours()-8, myDate.getHours()-7, myDate.getHours()-6, myDate.getHours()-5, myDate.getHours()-4, myDate.getHours()-3, myDate.getHours()-2, myDate.getHours()-1, myDate.getHours(), ];
For time processing, it is recommended to introduce the moment library. http://momentjs.com/docs/#/pa...
If you need the format of 2017-03-14-04-50-08:
var str = '2017/3/14 4:50:08 PM';
var arr = str.split(/[ ^d ]+/g).map(item => (parseInt(item, 10) < ; 10 ? '0' + parseInt(item, 10) : item )).join('-');
console.log(arr);
As for the addition and subtraction of time, as mentioned above, it is actually good to introduce libraries such as moment.js into the project.
Date.prototype.past = function(pattern, pastDays) {
};
var timeEnd = new Date();
timeEnd = timeEnd.getFullYear() + '/' + (timeEnd.getMonth() + 1) + '/' + timeEnd.getDate() + ' ' + timeEnd. getHours() + ':' + timeEnd.getMinutes();
You mean to push the current time forward 10 minutes, new Date(timeEnd).past('YYYY-MM-DD hh : mm : ss', 1/ (24*6));