如何通过在 Moment.js 中传递月份和年份来获取月份的开始日期和结束日期
How to get the start date and end date of a month by passing Month and Year in Moment.js
我正在使用 Moment.js 进行日历转换。是否可以通过传递月和年来获取该月的第一个和最后一个日期
我的年月格式是 - 10-18
,格式是 MM-YY
。
我想在 01 Oct 2018
中获取 10 月的第一个和最后一个日期。
我可以在 Moment 中将其格式化为我想要的日期,但不确定如何通过 10-18
.
获得一个月的第一个和最后一个日期
任何帮助建议都会很有帮助。
谢谢
R
很简单,只需使用 startOf
和 endOf
;)
小心,因为它会改变原始时刻。
const input = "10-18";
const output = moment(input, "MM-YY");
console.log('Start of the month:', output.startOf('month').format('LL'));
console.log('End of the month:', output.endOf('month').format('LL'));
<script src="https://momentjs.com/downloads/moment.js"></script>
这是文档:
我正在使用 Moment.js 进行日历转换。是否可以通过传递月和年来获取该月的第一个和最后一个日期
我的年月格式是 - 10-18
,格式是 MM-YY
。
我想在 01 Oct 2018
中获取 10 月的第一个和最后一个日期。
我可以在 Moment 中将其格式化为我想要的日期,但不确定如何通过 10-18
.
任何帮助建议都会很有帮助。
谢谢 R
很简单,只需使用 startOf
和 endOf
;)
小心,因为它会改变原始时刻。
const input = "10-18";
const output = moment(input, "MM-YY");
console.log('Start of the month:', output.startOf('month').format('LL'));
console.log('End of the month:', output.endOf('month').format('LL'));
<script src="https://momentjs.com/downloads/moment.js"></script>
这是文档: