i have the first day and last day of the month, the length of the current month i'm looking for a function that will give me all the appearances of any day in this month, i've seen some functions that gives the next occurrence but i want to be able to enter any day and see all is occurrences .. i guess it will be some kind of loop..i'm working on it as we speek but any help would be great..
$scope.recurrenceFields.by_year_day=$filter('date')($scope.fields.times.dateStart, 'yyyy');
$scope.recurrenceFields.by_month=$filter('date')($scope.fields.times.dateStart, 'M');
var correntDay = new Date();
var lastDayOfMonth = new Date(correntDay.getFullYear(), correntDay.getMonth()+1, 0);
var firstDayOfMonth = new Date(correntDay.getFullYear(), correntDay.getMonth(), 1);
function daysInMonth(month,year) {
return new Date($filter('date')($scope.fields.times.dateStart, 'yyyy'), $scope.recurrenceFields.by_month, 0).getDate();
}
Not quite sure what "all the appearances of any day in this month" means, but the following function returns all the occurrences of a particular day in a month given year, month and day number.
/* #param {number} year - calendar year
** #param {number} month - calendar month: 1-Jan, 2-Feb, etc.
** #param {number} dayNumber - day number: 0-Sunday, 1-Monday, etc.
** #returns {Array} Dates for all days in month of dayNumber
*/
function getAllDaysInMonth(year, month, dayNumber) {
var d = new Date(year, --month, 1);
var dates = [];
var daysToFirst = (dayNumber + 7 - d.getDay()) % 7;
var firstOf = new Date(d.setDate(d.getDate() + daysToFirst));
while (firstOf.getMonth() == month) {
dates.push(new Date(+firstOf));
firstOf.setDate(firstOf.getDate() + 7);
}
return dates;
}
// Return array of all Thursdays in July 2015
console.log(getAllDaysInMonth(2015, 7, 4));
// [Thu 02 Jul 2015,
// Thu 09 Jul 2015,
// Thu 16 Jul 2015,
// Thu 23 Jul 2015,
// Thu 30 Jul 2015]
// Get all Tuesdays in February 2000
console.log(getAllDaysInMonth(2000, 2, 2));
// [Tue 01 Feb 2000,
// Tue 08 Feb 2000,
// Tue 15 Feb 2000,
// Tue 22 Feb 2000,
// Tue 29 Feb 2000]
// Get all Sundays in December 2015
console.log(getAllDaysInMonth(2015, 12, 0));
// [Sun 06 Dec 2015,
// Sun 13 Dec 2015,
// Sun 20 Dec 2015,
// Sun 27 Dec 2015]
You can use this service :
angular.module('myApp.services')
.factory('dateUtils', function () {
return {
getIntervals: function (startTimestamp, endTimestamp, interval) {
if(!angular.isNumber(startTimestamp) || !angular.isNumber(endTimestamp) || !angular.isNumber(interval) || startTimestamp===0 || endTimestamp===0) {
return [];
}
var intervals = [];
var currentPeriod = startTimestamp;
while (currentPeriod <= endTimestamp) {
intervals.push(currentPeriod);
var currentPeriodDate = new Date(currentPeriod);
currentPeriodDate.setDate(currentPeriodDate.getDate() + interval);
currentPeriod = currentPeriodDate.getTime();
}
return intervals;
}
};
});
If you want all day between two dates, just use the service :
dateUtils.getIntervals(startDate, endDate, 1);
Related
I created a function to generate an array of dates arr in 1-month increments beginning at 1/1/2013 and going until now.
function getDateRange() {
var start = new Date('1/1/2013');
var today = new Date();
var arr = [start];
var next = new Date(start);
while (next < today) {
arr.push(next);
next = new Date(next.setMonth(next.getMonth() + 1));
}
Logger.log(arr);
Logger.log(arr.map(formatDate));
}
function formatDate(d) {
return Utilities.formatDate(d, 'MST', 'MMM-dd');
}
The function correctly generates arr, which looks like the following:
Jan 01 2013 00:00:00 GMT-0700 (MST),Fri Feb 01 2013 00:00:00 GMT-0700 (MST),Fri Mar 01 2013 00:00:00 GMT-0700 (MST),Mon Apr 01 2013 00:00:00 GMT-0600 (MDT),Wed May 01 2013 00:00:00 GMT-0600 (MDT)...
but then when I log arr.map(formatDate), I don't get the same dates starting at the 4th date:
Jan-01,Feb-01,Mar-01,Mar-31,Apr-30...
Any ideas why Utilities.formatDate is screwing up the dates?
function getDateRange() {
var start = new Date('1/1/2013');
var today = new Date();
var arr = [];
do {
arr.push(start);
start = new Date(start.setDate(start.getDate() + 1));
} while (start < today)
console.log(arr);
console.log(arr.map(formatDate));
}
function formatDate(date) {
return date.toLocaleString("en-us", {
month: "short",
timeZone: 'UTC'
}) + "-" + date.toLocaleString("en-us", {
day: "numeric",
timeZone: 'UTC'
});
}
I have a javascript function that takes in a number X and a date, and returns a new Date that is X number of days away:
function addDays(theDate, numDaysToAdd) {
var newDate = new Date();
return new Date(newDate.setDate(theDate.getDate() + numDaysToAdd));
}
I pass it a day that is Sat Jul 02 2016 16:03:06 GMT-0700 (Pacific Daylight Time) and a number 7, but the result I got was Thu Jun 09 2016 16:05:32 GMT-0700 (Pacific Daylight Time). Why is it giving me the correct date but wrong month?
The problem is that newDate is always created from the current date (new Date()). In other words, if this function is executed in June it will produce a date in June, then try to set a the day of the month as a offset from the input date.
You need to construct newDate as a copy of theDate:
function addDays(theDate, numDaysToAdd) {
var newDate = new Date(theDate);
newDate.setDate(theDate.getDate() + numDaysToAdd);
return newDate;
}
var d = new Date('Sat Jul 02 2016 16:03:06 GMT-0700 (Pacific Daylight Time)');
console.log(addDays(d, 7).toString());
You can add number of milliseconds to given date and it will generate correct date.
getTime() returns milliseconds from epoch.
offset = numDaysToAdd * 24 * 60 * 60 * 1000;
24: Hours in a day
60: Minutes in an hour
60: seconds in a minute
1000: milliseconds in a second
Date constructor takes milliseconds from epoch
function addDays(theDate, numDaysToAdd) {
var start = theDate.getTime();
var offset = numDaysToAdd * 24 * 60 * 60 * 1000;
return new Date(start + offset);
}
var today = new Date();
console.log(today, addDays(today, 10));
I am trying to calculate number of weeks in a month using moment js. But I am getting wrong results for some months like May 2015 and August 2015.
I am using this code.
var start = moment().startOf('month').format('DD');
var end = moment().endOf('month').format('DD');
var weeks = (end-start+1)/7;
weeks = Math.ceil(weeks);
Is there any prebuilt method in moment JS for getting number of weeks.
I have created this gist that finds all the weeks in a given month and year. By calculated the length of calendar, you will know the number of weeks.
https://gist.github.com/guillaumepiot/095b5e02b4ca22680a50
# year and month are variables
year = 2015
month = 7 # August (0 indexed)
startDate = moment([year, month])
# Get the first and last day of the month
firstDay = moment(startDate).startOf('month')
endDay = moment(startDate).endOf('month')
# Create a range for the month we can iterate through
monthRange = moment.range(firstDay, endDay)
# Get all the weeks during the current month
weeks = []
monthRange.by('days', (moment)->
if moment.week() not in weeks
weeks.push(moment.week())
)
# Create a range for each week
calendar = []
for week in weeks
# Create a range for that week between 1st and 7th day
firstWeekDay = moment().week(week).day(1)
lastWeekDay = moment().week(week).day(7)
weekRange = moment.range(firstWeekDay, lastWeekDay)
# Add to the calendar
calendar.push(weekRange)
console.log calendar
Can be easily done using raw javascript:
function getNumWeeksForMonth(year,month){
date = new Date(year,month-1,1);
day = date.getDay();
numDaysInMonth = new Date(year, month, 0).getDate();
return Math.ceil((numDaysInMonth + day) / 7);
}
You get the day index of the first day, add it to the number of days to compensate for the number of days lost in the first week, divide by 7 and use ceil to add 1 for the simplest overflow in the next week
It display the list of weeks in a month with 'moment.js'.
It has been written in typescript with angular 6+.
Install moment with 'npm i moment'
Inside the ts file.
weeks_in_month() {
let year = 2019; // change year
let month = 4; // change month here
let startDate = moment([year, month - 1])
let endDate = moment(startDate).endOf('month');
var dates = [];
var weeks = [];
var per_week = [];
var difference = endDate.diff(startDate, 'days');
per_week.push(startDate.toDate())
let index = 0;
let last_week = false;
while (startDate.add(1, 'days').diff(endDate) < 0) {
if (startDate.day() != 0) {
per_week.push(startDate.toDate())
}
else {
if ((startDate.clone().add(7, 'days').month() == (month - 1))) {
weeks.push(per_week)
per_week = []
per_week.push(startDate.toDate())
}
else if (Math.abs(index - difference) > 0) {
if (!last_week) {
weeks.push(per_week);
per_week = [];
}
last_week = true;
per_week.push(startDate.toDate());
}
}
index += 1;
if ((last_week == true && Math.abs(index - difference) == 0) ||
(Math.abs(index - difference) == 0 && per_week.length == 1)) {
weeks.push(per_week)
}
dates.push(startDate.clone().toDate());
}
console.log(weeks);
}
Result:
Array of date moments.
[Array(6), Array(7), Array(7), Array(7), Array(3)]
0: (6) [Mon Apr 01 2019 00:00:00 GMT+0530 (India Standard Time),
Tue Apr 02 2019 00:00:00 GMT+0530 (India Standard Time),
Wed Apr 03 2019 00:00:00 GMT+0530 (India Standard Time),
Thu Apr 04 2019 00:00:00 GMT+0530 (India Standard Time),
Fri Apr 05 2019 00:00:00 GMT+0530 (India Standard Time),
Sat Apr 06 2019 00:00:00 GMT+0530 (India Standard Time)]
1: (7) [Sun Apr 07 2019 00:00:00 GMT+0530 (India Standard Time),
Mon Apr 08 2019 00:00:00 GMT+0530 (India Standard Time),
Tue Apr 09 2019 00:00:00 GMT+0530 (India Standard Time),
Wed Apr 10 2019 00:00:00 GMT+0530 (India Standard Time),
Thu Apr 11 2019 00:00:00 GMT+0530 (India Standard Time),
Fri Apr 12 2019 00:00:00 GMT+0530 (India Standard Time),
Sat Apr 13 2019 00:00:00 GMT+0530 (India Standard Time)]
2: (7) [Sun Apr 14 2019 00:00:00 GMT+0530 (India Standard Time),
Mon Apr 15 2019 00:00:00 GMT+0530 (India Standard Time),
Tue Apr 16 2019 00:00:00 GMT+0530 (India Standard Time),
Wed Apr 17 2019 00:00:00 GMT+0530 (India Standard Time),
Thu Apr 18 2019 00:00:00 GMT+0530 (India Standard Time),
Fri Apr 19 2019 00:00:00 GMT+0530 (India Standard Time),
Sat Apr 20 2019 00:00:00 GMT+0530 (India Standard Time)]
3: (7) [Sun Apr 21 2019 00:00:00 GMT+0530 (India Standard Time),
Mon Apr 22 2019 00:00:00 GMT+0530 (India Standard Time),
Tue Apr 23 2019 00:00:00 GMT+0530 (India Standard Time),
Wed Apr 24 2019 00:00:00 GMT+0530 (India Standard Time),
Thu Apr 25 2019 00:00:00 GMT+0530 (India Standard Time),
Fri Apr 26 2019 00:00:00 GMT+0530 (India Standard Time),
Sat Apr 27 2019 00:00:00 GMT+0530 (India Standard Time)]
4: (3) [Sun Apr 28 2019 00:00:00 GMT+0530 (India Standard Time),
Mon Apr 29 2019 00:00:00 GMT+0530 (India Standard Time),
Tue Apr 30 2019 00:00:00 GMT+0530 (India Standard Time)]
EDIT:
NEW and hopefully very correct implementation:
function calcWeeksInMonth(date: Moment) {
const dateFirst = moment(date).date(1);
const dateLast = moment(date).date(date.daysInMonth());
const startWeek = dateFirst.isoWeek();
const endWeek = dateLast.isoWeek();
if (endWeek < startWeek) {
// Yearly overlaps, month is either DEC or JAN
if (dateFirst.month() === 0) {
// January
return endWeek + 1;
} else {
// December
if (dateLast.isoWeekday() === 7) {
// Sunday is last day of year
return endWeek - startWeek + 1;
} else {
// Sunday is NOT last day of year
return dateFirst.isoWeeksInYear() - startWeek + 1;
}
}
} else {
return endWeek - startWeek + 1;
}
}
Outputs the following values for the following dates:
calcWeeksInMonth(moment("2016-12-01")); // 5
calcWeeksInMonth(moment("2017-01-01")); // 6
calcWeeksInMonth(moment("2017-02-01")); // 5
calcWeeksInMonth(moment("2017-03-01")); // 5
calcWeeksInMonth(moment("2017-04-01")); // 5
calcWeeksInMonth(moment("2017-05-01")); // 5
calcWeeksInMonth(moment("2017-06-01")); // 5
calcWeeksInMonth(moment("2017-07-01")); // 6
calcWeeksInMonth(moment("2017-08-01")); // 5
calcWeeksInMonth(moment("2017-09-01")); // 5
calcWeeksInMonth(moment("2017-10-01")); // 6
calcWeeksInMonth(moment("2017-11-01")); // 5
calcWeeksInMonth(moment("2017-12-01")); // 5
calcWeeksInMonth(moment("2018-01-01")); // 5
OLD and very incorrect implementation:
calcWeeksInMonth(date) {
const dateFirst = moment(date).date(1)
const dateLast = moment(date).date(date.daysInMonth())
const startWeek = dateFirst.week()
const endWeek = dateLast.week()
if (endWeek < startWeek) {
return dateFirst.weeksInYear() - startWeek + 1 + endWeek
} else {
return endWeek - startWeek + 1
}
}
This seems to output correct results, feedback welcome if there is something I missed!
function getWeekNums(momentObj) {
var clonedMoment = moment(momentObj), first, last;
// get week number for first day of month
first = clonedMoment.startOf('month').week();
// get week number for last day of month
last = clonedMoment.endOf('month').week();
// In case last week is in next year
if( first > last) {
last = first + last;
}
return last - first + 1;
}
javaScript version here
var year = 2021
var month = 6
var startDate = moment([year, month])
//Get the first and last day of the month
var firstDay = moment(startDate).startOf('month')
var endDay = moment(startDate).endOf('month')
//Create a range for the month we can iterate through
var monthRange = moment.range(firstDay, endDay)
//Get all the weeks during the current month
var weeks = []
var indexOf = [].indexOf;
monthRange.by('days', function (moment) {
var ref;
if (ref = moment.week(), indexOf.call(weeks, ref) < 0) {
return weeks.push(moment.week());
}
});
var calendar, firstWeekDay, i, lastWeekDay, len, week, weekRange;
calendar = [];
for (i = 0, len = weeks.length; i < len; i++) {
week = weeks[i];
// Create a range for that week between 1st and 7th day
firstWeekDay = moment().week(week).day(0);
lastWeekDay = moment().week(week).day(6);
weekRange = moment.range(firstWeekDay, lastWeekDay);
// Add to the calendar
calendar.push(weekRange);
}
This is the best way out , works well
moment.relativeTime.dd = function (number) {
// round to the closest number of weeks
var weeks = Math.round(number / 7);
if (number < 7) {
// if less than a week, use days
return number + " days";
} else {
// pluralize weeks
return weeks + " week" + (weeks === 1 ? "" : "s");
}
}
Source:How to get duration in weeks with Moment.js?
I have not seen a solution that works in all circumstances. I tried all of these but they all are flawed in one way or another. Ditto with several moment.js github threads. This was my crack at it:
getNumberOfWeeksInMonth = (momentDate) => {
const monthStartWeekNumber = momentDate.startOf('month').week();
const distinctWeeks = {
[monthStartWeekNumber]: true
};
let startOfMonth = momentDate.clone().startOf('month');
let endOfMonth = momentDate.clone().endOf('month');
// this is an 'inclusive' range -> iterates through all days of a month
for (let day = startOfMonth.clone(); !day.isAfter(endOfMonth); day.add(1, 'days')) {
distinctWeeks[day.week()] = true
}
return Object.keys(distinctWeeks).length;
}
function weeksInMonth(date = null){
let firstDay = moment(date).startOf('month');
let endDay = moment(date).endOf('month');
let weeks = [];
for (let i = firstDay.week(); i <= endDay.week(); i++){
weeks.push(i)
}
return weeks;
}
Here is a simple way of doing it (based on a solution posted above):
const calcWeeksInMonth = (momentDate) => {
const dateFirst = moment(momentDate).date(1)
const dateLast = moment(momentDate).date(momentDate.daysInMonth())
const startWeek = dateFirst.isoWeek()
const endWeek = dateLast.isoWeek()
if (endWeek < startWeek) {
// cater to end of year (dec/jan)
return dateFirst.weeksInYear() - startWeek + 1 + endWeek
} else {
return endWeek - startWeek + 1
}
}
As far as I can tell, it works correctly for any date thrown at it, but feedback is always welcome!
Throwing this into the mix
import moment from "moment";
export const calcWeeksInMonth = date => {
let weekMonthEnds = moment(date)
.date(moment(date).daysInMonth())
.week();
let weekMonthStarts = moment(date)
.date(1)
.week();
return weekMonthEnds < weekMonthStarts
? moment(date).isoWeeksInYear() - weekMonthStarts + 1
: weekMonthEnds - weekMonthStarts + 1;
};
var month = moment().month();
var startOfMonth = month.startOf("month");
var endOfMonth = month.endOf("month");
var startWeekNumber = startOfMonth.isoWeek();
var endWeekNumber = endOfMonth.isoWeek();
var numberOfWeeks = (endWeekNumber - startWeekNumber + 1);
console.log(numberOfWeeks);
If you have selectedDate value that is give you opportunity to detect which month is active now:
private calculateNumberOfWeeks(): number {
const end = moment(this.selectedDate).endOf('month');
const startDay = moment(this.selectedDate)
.startOf('month')
.day();
const endDay = end.day();
const endDate = end.date();
return (startDay - 1 + endDate + (endDay === 0 ? 0 : 7 - endDay)) / 7;
}
/UPDATE/
Solution below did not take in consideration jump to the new year.
Here is the improved solution.
const getNumberOfWeeksInAMonth = (currentMoment: moment.Moment) => {
const currentMomentCopy = cloneDeep(currentMoment)
const startOfMonth = currentMomentCopy.startOf('month')
const startOfISOWeek = startOfMonth.startOf('isoWeek')
let numberOfWeeks = 0;
do {
numberOfWeeks++
MomentManager.addWeek(startOfISOWeek)
} while (currentMoment.month() === startOfISOWeek.month())
return numberOfWeeks;
}
I have found another solution with momentjs.
const getNumberOfWeeksInMonth = (moment: moment.Moment) => {
const startWeek = moment.startOf('month').isoWeek()
const endWeek = moment.endOf('month').isoWeek()
return endWeek - startWeek + 1
}
I have two dates and want to save the days in between (plus start and end date) in an array
var date1 = new Date("Sep 23, 2013 12:00:00"); // Monday
var date2 = new Date("Sep 26, 2013 12:00:00"); // Thursday
var alldates = [];
for (var i=0; date1 <= date2; date1.setDate(date1.getDate() + 1), i++) {
alldates.push(date1);
}
alert(alldates.join('\n'));
With this code alert(alldates.join('\n')); shows the following
Fri Sep 27 2013 12:00:00 GMT+0200
Fri Sep 27 2013 12:00:00 GMT+0200
Fri Sep 27 2013 12:00:00 GMT+0200
Fri Sep 27 2013 12:00:00 GMT+0200
I am new to Javascript and want to get further understanding, so thank you for any explanation why the alert does not show
Mon Sep 23 2013 12:00:00 GMT+0200
Tue Sep 24 2013 12:00:00 GMT+0200
Wed Sep 25 2013 12:00:00 GMT+0200
Thu Sep 26 2013 12:00:00 GMT+0200
The problem you have is that you push references to the date1 object. When you change the date on it in your loop, you update the object, but all references still point to the same object.
You need to either push a text representation of your date, or a copy of your date1 object
for (var i=0; date1 <= date2; date1.setDate(date1.getDate() + 1), i++) {
alldates.push(new Date(date1));
}
alert(alldates.join('\n'));
As suggested, with a while loop
while( date1 <= date2 ) {
alldates.push(new Date(date1));
date1.setDate( date1.getDate() +1 );
}
Your array is storing the references for the single date object and everytime when setDate is called each of them are getting updated with new date value.
So it will be better to push the new date object in array like this,
var date1 = new Date("Sep 23, 2013 12:00:00"); // Monday
var date2 = new Date("Sep 26, 2013 12:00:00"); // Thursday
var alldates = [];
// pushing first date
alldates.push(new Date(date1.setDate(date1.getDate())));
for (var i=0; date1 <= date2; i++) {
alldates.push(new Date(date1.setDate(date1.getDate() + 1)));
}
alert(alldates.join('\n'));
To echo the other answers, the issue is that the element being pushed to the array isn't a value which stays the same - it refers to a Date object which changes in the loop, so all references to date1 stored in alldates are set to the final value of date1.
The accepted answer does the job, but it also mutates the value of date1. The OP set up the code with this side effect, which suggests that this isn't a problem for their use case. But if you'd prefer to not mutate date1, here's an alternative ES6-flavored, side effect-free approach:
const date1 = new Date("Sep 23, 2013 12:00:00"); // Monday
const date2 = new Date("Sep 26, 2013 12:00:00"); // Thursday
const msPerDay = 1000 * 60 * 60 * 24; // 86400000
const inclusiveDateLength = (date2 - date1) / msPerDay + 1; // 4
const allDates = Array.from(Array(inclusiveDateLength), (_, i) => {
const newDate = new Date(date1);
newDate.setDate(date1.getDate() + i);
return newDate;
});
console.log(allDates.join("\n"));
Explanation: We create an array, fill it new Dates, and increment the day of the month of each of those Dates with Date.prototype.setDate(). A cool feature of Array.from is that it accepts a map function as its second argument. We leverage the index value (i) in the map function to increment the day of the month of each date - note that this also works for wrap-arounds, such as Sep 29 to Oct 02.
When the Temporal API becomes available, it will probably offer a better solution to this problem.
How can I obtain the last day of the month with the timestamp being 11:59:59 PM?
function LastDayOfMonth(Year, Month) {
return new Date((new Date(Year, Month, 1)) - 1);
}
console.log(LastDayOfMonth(2009, 11))
Example:
> LastDayOfMonth(2009, 11)
Mon Nov 30 2009 23:59:59 GMT+0100 (CET)
This will give you last day of current month.
var t= new Date();
alert(new Date(t.getFullYear(), t.getMonth() + 1, 0, 23, 59, 59));
var d = new Date();
console.log(d);
d.setMonth(d.getMonth() + 1); // set month as next month
console.log(d);
d.setDate(0); // get the last day of previous month
console.log(d);
Here is output from the code above:
Thu Oct 03 2013 11:34:59 GMT+0100 (GMT Daylight Time)
Sun Nov 03 2013 11:34:59 GMT+0000 (GMT Standard Time)
Thu Oct 31 2013 11:34:59 GMT+0000 (GMT Standard Time)
var d = new Date();
m = d.getMonth(); //current month
y = d.getFullYear(); //current year
alert(new Date(y,m,1)); //this is first day of current month
alert(new Date(y,m+1,0)); //this is last day of current month
var month = 1; // 1 for January
var d = new Date(2015, month, 0);
console.log(d); // last day in January
Sometimes all you have is a text version of the current month, ie: April 2017.
//first and last of the current month
var current_month = "April 2017";
var arrMonth = current_month.split(" ");
var first_day = new Date(arrMonth[0] + " 1 " + arrMonth[1]);
//even though I already have the values, I'm using date functions to get year and month
//because month is zero-based
var last_day = new Date(first_day.getFullYear(), first_day.getMonth() + 1, 0, 23, 59, 59);
//use moment,js to format
var start = moment(first_day).format("YYYY-MM-DD");
var end = moment(last_day).format("YYYY-MM-DD");
Last day of the month
now = new Date
lastDayOfTheMonth = new Date(1900+now.getYear(), now.getMonth()+1, 0)
Most of these answers are missing one thing or another. After playing with most of them I came up with the following that gives you the last possible millisecond of the month.
let testDate = new Date();
console.log(getMonthEnd(testDate));
function getMonthEnd(value) {
return new Date(value.getFullYear(), value.getMonth() + 1, 0, 23, 59, 59, 999);
}
Probably missing something in this one too but seems to cover all my requirements.
Calendar cal = Calendar.getInstance();
cal.set(Calendar.DATE, cal.getActualMaximum(Calendar.DATE));
Date lastDayOfMonth = cal.getTime();
Do not forget month started with 0 so +1 in month too.
let enddayofmonth = new Date(year, month, 0).getDate();