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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
|
var initDate = function(sdate) { if( sdate == '' || typeof (sdate) == 'undefined' ) return new Date(); else return new Date(sdate); }
var getYear = function(sdate) { return initDate(sdate).getFullYear(); }
var getMonth = function(sdate) { return initDate(sdate).getMonth() + 1; }
var getDate = function(sdate) { return initDate(sdate).getDate(); }
var getDates = function(sdate) { let curdate = initDate(sdate); let month = curdate.getMonth() + 1; let date = curdate.getDate(); month = month < 10?'0'+month:month; date = date < 10?'0'+date:date; return curdate.getFullYear()+'-'+month+'-'+date; }
var getHours = function(sdate) { return initDate(sdate).getHours(); }
var getMinutes = function(sdate) { return initDate(sdate).getMinutes(); }
var getSeconds = function(sdate) { return initDate(sdate).getSeconds(); }
var getMilliseconds = function(sdate) { return initDate(sdate).getMilliseconds(); }
var getTime = function(sdate) { let curdate = initDate(sdate); let hours = curdate.getHours(); let minutes = curdate.getMinutes(); let seconds = curdate.getSeconds(); hours = hours < 10?'0'+hours:hours; minutes = minutes < 10?'0'+minutes:minutes; seconds = seconds < 10?'0'+seconds:seconds; return hours+':'+minutes+':'+seconds; }
var getDateTime = function(sdate) { let curdate = initDate(sdate); let month = curdate.getMonth() + 1; let date = curdate.getDate(); let hours = curdate.getHours(); let minutes = curdate.getMinutes(); let seconds = curdate.getSeconds(); month = month < 10?'0'+month:month; date = date < 10?'0'+date:date; hours = hours < 10?'0'+hours:hours; minutes = minutes < 10?'0'+minutes:minutes; seconds = seconds < 10?'0'+seconds:seconds; return curdate.getFullYear()+'-'+month+'-'+date+' '+hours+':'+minutes+':'+seconds; }
var getDiffDate = function(sdate,edate) { return (getTimeStamp(getDates(edate)) - getTimeStamp(getDates(sdate)))/(24*60*60*1000); }
var getDay = function(sdate) { let day = initDate(sdate).getDay(); if(day == 0) return 7; else return day; }
var getWof = function(sdate,start) { if(start < 1 || start > 7) return false; let end = start - 1; if(end == 0) end = 7; let firstDate = getDates(getYear(sdate)+''); let firstDay = getDay(firstDate); if(end < firstDay) end += 7; let firstWeekDays = end - firstDay + 1; let date = getDates(sdate); let diffDate = getDiffDate(firstDate,date) + 1; if(diffDate <= firstWeekDays) return 1; let subDate = diffDate - firstWeekDays; let weeks = Math.floor(subDate/7); if(subDate%7) weeks++; return weeks+1; }
var getTimeStamp = function(sdate) { return initDate(sdate).getTime(); }
var setYear = function(sdate,nums) { let curdate = initDate(sdate); return curdate.setFullYear(curdate.getFullYear() + nums); }
var setMonth = function(sdate,nums) { let curdate = initDate(sdate); return curdate.setMonth(curdate.getMonth() + nums); }
var setDate = function(sdate,nums) { let curdate = initDate(sdate); return curdate.setDate(curdate.getDate() + nums); }
var setHours = function(sdate,nums) { let curdate = initDate(sdate); return curdate.setHours(curdate.getHours() + nums); }
var setMinutes = function(sdate,nums) { let curdate = initDate(sdate); return curdate.setMinutes(curdate.getMinutes() + nums); }
var setSeconds = function(sdate,nums) { let curdate = initDate(sdate); return curdate.setSeconds(curdate.getSeconds() + nums); }
var isLeapYear = function(sdate) { let year = getYear(sdate); if(year%100) return year%4?0:1; else return year%400?0:1; }
var getDaysInMonth = function(sdate) { let daysInMonth = [31,28,31,30,31,30,31,31,30,31,30,31]; let month = getMonth(sdate); let days = daysInMonth[month-1]; if(month == 2 && isLeapYear(sdate)) days++; return days; }
|