bookCommon.js
1.98 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
module.exports ={
//时间戳转化日期
changedate:function(timestamp){
var date = new Date(timestamp);//时间戳为10位需*1000,时间戳为13位的话不需乘1000
var Y= date.getFullYear();
var M =date.getMonth()+1;
var D =date.getDate();
var h = date.getHours();
var m = date.getMinutes();
var s = date.getSeconds();
var w=date.getDay();
return {year:Y,month:M,day:D,hour:h,minute:m,second:s,week:w};
},
//获取星期
getweek:function (index) {
var week=['周日','周一','周二','周三','周四','周五','周六'];
return week[index]
},
//获取某月天数,月份不需要减1
getMonthdays:function(year,month){
var d = new Date(year,month,0);
return d.getDate();
},
//获取某一天是星期几,月份需减1
getdayweek:function(year,month,day){
var tmpdate=new Date(year,month,day);
return tmpdate.getDay()
},
//判断是否是整数
isInteger:function (obj) {
return obj%1 === 0
},
//时间转化时间戳
gettimestamp:function(stringTime){
var date = new Date(stringTime.replace(/-/g, '/'));
var timestamp2=Date.parse(date)/1000;
return timestamp2
},
//日期转换 8月8日----08-08
get_date:function(thiadate){
var thismoth=thiadate.split('月')[0];
var thisday=thiadate.split('月')[1].slice(0,-1);
var timedate=(parseInt(thismoth)<10 ? '0'+thismoth : thismoth)+'-'+(parseInt(thisday)<10 ? '0'+thisday : thisday);
return timedate;
},
//日期转换 08-08----8月8日
getdate_num:function(thisdate){
var thismonth=thisdate.split('-')[0][0]=='0' ? thisdate.split('-')[0][1] : thisdate.split('-')[0];
var thisday=thisdate.split('-')[1][0]=='0' ? thisdate.split('-')[1][1] : thisdate.split('-')[1];
console.log()
var timedate=thismonth+'月'+thisday+'日';
return timedate;
}
}