custom-time
Version:
高度自定义化日期插件
55 lines (44 loc) • 2.02 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
exports.default = function (date, format) {
var df = new DateFormat(date);
df.initDate();
_masksArr2.default.forEach(function (value, key) {
if (format.includes(key)) {
var formatTime = key.length > 1 ? df.formatNumber(df[value]) : df[value];
format = format.replace(key, formatTime);
}
});
return format;
};
var _masksArr = require('./masksArr');
var _masksArr2 = _interopRequireDefault(_masksArr);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var DateFormat = function () {
function DateFormat(date) {
_classCallCheck(this, DateFormat);
this._date = new Date(date);
}
_createClass(DateFormat, [{
key: 'formatNumber',
value: function formatNumber(num) {
return num < 10 ? '0' + num : num;
}
}, {
key: 'initDate',
value: function initDate() {
this.fullYear = this._date.getFullYear();
this.month = this._date.getMonth() + 1;
this.date = this._date.getDate();
this.hours = this._date.getHours();
this.minutes = this._date.getMinutes();
this.seconds = this._date.getSeconds();
}
}]);
return DateFormat;
}();
//# sourceMappingURL=date-format.js.map