英文:
Based on month and year get the First day of the month and last day of month
问题
我是新手使用extjs。我有月份和年份。我需要根据月份和年份获取当月的第一天和最后一天。
我知道如何获取当前月份的第一天和最后一天。
var date = new Date();
var firstDay = new Date(date.getFullYear(), date.getMonth(), 1);
var lastDay = new Date(date.getFullYear(), date.getMonth() + 1, 0);
例如,在下面的例子中,我有月份和年份,需要获取该月的第一天和最后一天。
var Month = '三月';
var Year = 2023;
英文:
I am new to extjs. i have month and year. i need 1st day of the month and last day of the month based on month and year
i know how to get 1st day and last day of the current month
var date = new Date();
var firstDay = new Date(date.getFullYear(), date.getMonth(), 1);
var lastDay = new Date(date.getFullYear(), date.getMonth() + 1, 0);
for example below i have month and year.. need to get first and last day of the month
var Month = 'March'
var Year = 2023
答案1
得分: 0
function getFirstDayOfMonth(year, month) {
return new Date(year, month, 1);
}
const firstDayJanuary = getFirstDayOfMonth(2023, 0);
console.log('Full Date with First Day : ' + firstDayJanuary);
console.log("First Day of January 2023 is - " + firstDayJanuary.getDay());
function getLastDayOfMonth(year, month) {
return new Date(year, month + 1, 0);
}
const lastDayJan = getLastDayOfMonth(2023, 0);
console.log('Full Date with last Day : ' + lastDayJan);
console.log("Last Day of January 2023 is - " + lastDayJan.getDay());
Output :
Full Date with First Day : Sun Jan 01 2023 00:00:00 GMT+0000 (Coordinated Universal Time)
First Day of January 2023 is - 0 /*0 Indicate Sunday*/
Full Date with last Day : Tue Jan 31 2023 00:00:00 GMT+0000 (Coordinated Universal Time)
Last Day of January 2023 is - 2 /*2 Indicate Tuesday*/
英文:
function getFirstDayOfMonth(year, month) {
return new Date(year, month, 1);
}
const firstDayJanuary = getFirstDayOfMonth(2023, 0);
console.log('Full Date with First Day : '+firstDayJanuary);
console.log("First Day of January 2023 is - "+ firstDayJanuary.getDay());
function getLastDayOfMonth(year, month) {
return new Date(year, month + 1, 0);
}
const lastDayJan = getLastDayOfMonth(2023, 0);
console.log('Full Date with last Day : '+lastDayJan);
console.log("Last Day of January 2023 is - "+ lastDayJan.getDay());
Output :
Full Date with First Day : Sun Jan 01 2023 00:00:00 GMT+0000 (Coordinated Universal Time)
First Day of January 2023 is - 0 /*0 Indicate Sunday*/
Full Date with last Day : Tue Jan 31 2023 00:00:00 GMT+0000 (Coordinated Universal Time)
Last Day of January 2023 is - 2 /*2 Indicate Tuesday*/
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论