10 examples of 'javascript get last day of month' in JavaScript

Every line of 'javascript get last day of month' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
64function endofmonth() {
65 var curr = new Date; // get current date
66 var lastday = new Date(curr.setDate(30));
67 var result = lastday.getFullYear()+"-"+(lastday.getMonth() + 1) + "-"
68 + lastday.getDate();
69 return result;
70}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

202function last_month_day() {
203 var list = [];
204 var date = getFormatDate(new Date());
205 var year = date.split("-")[0];
206 var mouth = date.split("-")[1];
207 var day = date.split("-")[2]-1;
208 for (var i=0;i<30;i++){
209 var objM = mouth;
210 var objD = day-i;
211 if(objD<=0){
212 objD = objD+30;
213 objM = mouth -1;
214 objM = "0"+objM
215 }
216
217 var obj = year+"-"+objM +"-"+objD;
218 list.push(obj)
219 }
220 return list;
221}
42export function getDaysInMonth (d) {
43 const resultDate = getFirstDayOfMonth(d);
44
45 resultDate.setMonth(resultDate.getMonth() + 1);
46 resultDate.setDate(resultDate.getDate() - 1);
47
48 return resultDate.getDate();
49}
96function getDaysInMonth(d) {
97 var resultDate = getFirstDayOfMonth(d);
98 resultDate.setMonth(resultDate.getMonth() + 1);
99 resultDate.setDate(resultDate.getDate() - 1);
100 return resultDate.getDate();
101}
44function getDaysInMonth(year, month) {
45 return 32 - new Date(UTC(year, month, 32)).getUTCDate();
46};
15function firstDay(month, year) {
16 var day = new Date(year, month - 1, 1).getDay();
17 return (day === 0) ? 7 : day;
18}
12getLastMonday(): Date {
13 let nowDate: Date = this.clock.getDate();
14 let dayOfWeek = nowDate.getDay() ? nowDate.getDay() : 7;
15 let daysOffsetInMillis = (dayOfWeek - 1) * WeekCalculator.MILLIS_IN_DAY;
16 let lastMonday = new Date(nowDate.getTime() - daysOffsetInMillis);
17
18 lastMonday.setHours(0);
19 lastMonday.setMinutes(0);
20 lastMonday.setSeconds(0);
21 lastMonday.setMilliseconds(0);
22
23 return lastMonday;
24}
165function last_year_month() {
166 var list = [];
167 var date = getFormatDate(new Date());
168 var year = date.split("-")[0];
169 var mouth = date.split("-")[1];
170 for (var i=0;i<12;i++){
171 var objM = mouth-i;
172 var objY = year;
173 if(objM<=0){
174 objM = objM+12;
175 objY = year -1;
176 }
177 if(objM<10){
178 objM = "0"+objM;
179 }
180 var obj = objY +"-"+objM;
181 list.push(obj)
182
183 }
184 return list;
185}
167function getLastDayOfMonth(date) {
168 return date && moment(date).endOf('month');
169}
120export function getLastDayOfMonth(date) {
121 return date && moment(date).endOf('month');
122}

Related snippets