[英]How to return last day of month in ngx-bootstrap datepicker angular
Below is my code where I need to display calendar with month and year and when user selects month and year it should display last day of that month with year.下面是我的代码,我需要显示带有月份和年份的日历,当用户选择月份和年份时,它应该显示该月份的最后一天和年份。 I am able to get the date as 01 June 2022 using below code, where as I need date as 30 June 2022我可以使用以下代码获得日期为 2022 年 6 月 1 日,因为我需要日期为 2022 年 6 月 30 日
Quickest way is using a library like moment
(depreacated) or dayjs
.最快的方法是使用像moment
(deprecated) 或dayjs
这样的库。 Take the date you get from datepicker, and use it with the library to get the end date of the month-year.获取您从 datepicker 获得的日期,并将其与库一起使用以获取月年的结束日期。
Change the dateInputFormat
to YYYY-MM-DDDD
in the bsConfig
.在bsConfig
dateInputFormat
更改为YYYY-MM-DDDD
。
Inside your getDate()
function process the datePicker date to get proper format.在您的getDate()
函数中处理 datePicker 日期以获得正确的格式。
Example code:示例代码:
const date = '2022-06-01';
console.log('Print date: ', moment(date).endOf('month').format('DD MM YYYY'));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.