getDate.js
1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
export const getCurrentDate = function () {
let todayDate = new Date();
let date = todayDate.getDate();
let month = todayDate.getMonth() + 1;
let year = todayDate.getYear();
var dateweek = "";
if (navigator.appName == "Netscape") {
dateweek = dateweek + (1900 + year) + "/" + month + "/" + date + "";
}
if (navigator.appVersion.indexOf("MSIE") != -1) {
dateweek = dateweek + year + "年" + month + "月" + date + "日 ";
}
return dateweek;
}
export const getFormatDate = (timestamp = '') => {
timestamp = parseInt(timestamp + '000');
var newDate = new Date(timestamp);
Date.prototype.format = function (format) {
var date = {
'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()
};
if (/(y+)/i.test(format)) {
format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
}
for (var k in date) {
if (new RegExp('(' + k + ')').test(format)) {
format = format.replace(RegExp.$1, RegExp.$1.length == 1 ?
date[k] : ('00' + date[k]).substr(('' + date[k]).length));
}
}
return format;
}
// return newDate.format('yyyy-MM-dd h:m');
return newDate.format('yyyy/M/d');
}
//获取当前月的第一天
export const getCurrentMonthFirst = () => {
let date = new Date();
date.setDate(1);
return date;
}
//获取当前月的最后一天
export const getCurrentMonthLast = () => {
let date = new Date();
let currentMonth = date.getMonth();
let nextMonth = ++currentMonth;
let nextMonthFirstDay = new Date(date.getFullYear(), nextMonth, 1);
let oneDay = 1000 * 60 * 60 * 24;
return new Date(nextMonthFirstDay - oneDay);
}