123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- const oneMinute = 1000 * 60;
- const oneHour = oneMinute * 60;
- const oneDay = oneHour * 24;
- const oneWeek = oneDay * 7;
- const oneMonth = oneDay * 30;
- Date.prototype.minusDays = function (days) {
- return this.minusMillis(oneDay * days);
- };
- Date.prototype.plusDays = function (days) {
- return this.plusMillis(oneDay * days);
- };
- Date.prototype.minusHours = function (hours) {
- return this.minusMillis(oneHour * hours);
- };
- Date.prototype.plusHours = function (hours) {
- return this.plusMillis(oneHour * hours);
- };
- Date.prototype.minusMinutes = function (minutes) {
- return this.minusMillis(oneMinute * minutes);
- };
- Date.prototype.plusMinutes = function (minutes) {
- return this.plusMillis(oneMinute * minutes);
- };
- Date.prototype.minusMillis = function(millis) {
- let time = this.getTime() - millis;
- let newDate = new Date();
- newDate.setTime(time);
- return newDate;
- };
- Date.prototype.plusMillis = function(millis) {
- let time = this.getTime() + millis;
- let newDate = new Date();
- newDate.setTime(time);
- return newDate;
- };
- Date.prototype.setMinTime = function () {
- this.setHours(0);
- this.setMinutes(0);
- this.setSeconds(0);
- this.setMilliseconds(0);
- return this;
- };
- Date.prototype.setMaxTime = function () {
- this.setHours(23);
- this.setMinutes(59);
- this.setSeconds(59);
- this.setMilliseconds(999);
- return this;
- };
- Date.prototype.formatDate = function () {
- return this.getFullYear() + "-" + addZero(this.getMonth() + 1) + "-" + addZero(this.getDate());
- };
- Date.prototype.formatTime = function () {
- return addZero(this.getHours()) + ":" + addZero(this.getMinutes()) + ":" + addZero(this.getSeconds());
- };
- Date.prototype.formatDateTime = function (split = ' ') {
- return this.formatDate() + split + this.formatTime();
- };
- class DateUtil {
-
- static parseDate(str) {
- return new Date(str.replace(/-/g, '/'));
- }
- static formatMillis(millis) {
- return moment(millis).format('YYYY-M-D H:m:s');
- }
- static firstDayOfMonth() {
- const date = new Date();
- date.setDate(1);
- date.setMinTime();
- return date;
- }
- static convertToJalalian(date) {
- return date && moment.isMoment(date) ? date.format('jYYYY/jMM/jDD HH:mm:ss') : null;
- }
- }
|