获取 Luxon 季度的持续时间

ris*_*ide 0 javascript typescript luxon

我正在尝试获取 Luxon 中任意“季度”的持续时间(或开始和结束日期)。

例如,假设我希望仅知道第三季度的开始日期和结束日期:

const quarterInQuestion = 3;

const startDateOfQuarter = DateTime.fromFormat(quarterInQuestion.toString(), 'q');
Run Code Online (Sandbox Code Playgroud)

这将为我提供该季度的开始日期,但我如何才能获得结束日期。我已经研究了持续时间和间隔,但似乎还没有任何进展。

非常感谢!

Ale*_*yne 5

我想你想要的方法endOf你可以通过你想要从日期结束的时间段。

const startDateOfQuarter = DateTime.fromFormat('3', 'q');
const endDateOfQuarter = startDateOfQuarter.endOf('quarter')
Run Code Online (Sandbox Code Playgroud)