最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to get the day of the year [1-365|366] with Luxon? - Stack Overflow

programmeradmin3浏览0评论

Is it possible to get the day of the year in the 1-365|366 range from a Luxon DateTime object?

I'm looking for a solution that doesn't involve puting the value. So something similar to DateTime.day, DateTime.weekNumber, DateTime.month etc. or using DateTime.toFormat() would be awesome.

Is it possible to get the day of the year in the 1-365|366 range from a Luxon DateTime object?

I'm looking for a solution that doesn't involve puting the value. So something similar to DateTime.day, DateTime.weekNumber, DateTime.month etc. or using DateTime.toFormat() would be awesome.

Share Improve this question edited Sep 2, 2022 at 9:49 lampshade asked Sep 2, 2022 at 6:41 lampshadelampshade 2,8167 gold badges45 silver badges89 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 10

In Luxon, you can simply use ordinal:

Get the ordinal (meaning the day of the year)

Example:

console.log(luxon.DateTime.now().ordinal)
<script src="https://cdn.jsdelivr/npm/[email protected]/build/global/luxon.min.js"></script>

In a format string, use "o" (ordinal) for the day of the year:

console.log(luxon.DateTime.now().toFormat("o"));
<script src="https://cdn.jsdelivr/npm/[email protected]/build/global/luxon.js"></script>

发布评论

评论列表(0)

  1. 暂无评论