Open xyzdata opened 6 years ago
Date.prototype.format = function (format) {
/*
* format="yyyy-MM-dd hh:mm:ss";
*/
// this = object self
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()
};
// Regex Group
if (/(y+)/.test(format)) {
// RegExp.$1 & replace
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;
};
/*
const date = new Date();
const f = "yyyy-MM-dd hh:mm:ss";
f.replace($1, date.getFullYear());
// "2017-MM-dd hh:mm:ss"
// 分组(Grouping)与反向引用(back references)
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/RegExp#grouping-back-references
//RegExp.$1-$9
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/RegExp/n
var re = /(\w+)\s(\w+)/;
var str = 'John Smith';
str.replace(re, '$2, $1'); // "Smith, John"
RegExp.$1; // "John"
RegExp.$2; // "Smith"
f = "yyyy-MM-dd hh:mm:ss";
r = /(\w+)\-(\w+)/;
f.replace(r, '$2, $1');
// "MM, yyyy-dd hh:mm:ss"
f.replace(r, '$1, $2, $3, $4');
// "yyyy, MM, $3, $4-dd hh:mm:ss"
RegExp();
// /(?:)/
/(y+)/.test(f);
// true
RegExp.$1
// "yyyy"
RegExp.$2
""
/(y+)/.test(f);
true
f.replace(`$1`, `2017`);
"yyyy-MM-dd hh:mm:ss"
/(y+)/.test(f);
true
f.replace(`${RegExp.$1}`, `2017`);
"2017-MM-dd hh:mm:ss"
/(y+)/.test(f);
true
f.replace(`${$1}`, `2017`);
"yyyy-MM-dd hh:mm:ss"
// RegExp.lastMatch ($&)
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastMatch
// RegExp.lastParen ($+)
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastParen
// RegExp.leftContext ($`)
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/RegExp/leftContext
// RegExp.rightContext ($')
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/RegExp/rightContext
*/
const format = `yyyy-MM-dd hh:mm:ss`;
const date = new Date();
// Tue Sep 26 2017 19:58:34 GMT+0800 (中国标准时间)
date.format(`yyyy-MM-dd hh:mm:ss`);
// "2017-09-26 19:58:34"
date.format(`yyyy-MM-dd`);
// "2017-09-26"
date.format(`yyyy-MM-dd `);
// "2017-09-26 "
Angular2017
https://app.pluralsight.com/library/courses/angular-2-first-look/
https://app.pluralsight.com/library/courses/angular-2-first-look/transcript https://app.pluralsight.com/library/courses/angular-2-first-look/exercise-files
https://app.pluralsight.com/library/courses/angular-2-first-look/discussion
https://app.pluralsight.com/library/courses/angular-2-first-look/learning-check https://app.pluralsight.com/score/learning-check/angular-2-first-look/next
https://app.pluralsight.com/library/courses/angular-2-first-look/recommended-courses