时刻 => 第一、第二
看不到 luxon 不提供这种格式。有什么建议或发现吗?
luxon 对此没有内置支持,但您可以编写如下所示的自定义逻辑。
// Import the DateTime class from Luxon
const DateTime = luxon.DateTime;
// Function to add ordinal suffix to day number
function addOrdinal(number) {
const suffixes = ['th', 'st', 'nd', 'rd'];
const v = number % 100;
return number + (suffixes[(v - 20) % 10] || suffixes[v] || suffixes[0]);
}
const date = DateTime.local(2023, 1, 1);
// Format the date as "1st Jan"
const formattedDate = `${addOrdinal(date.day)} ${date.toFormat('LLL')}`;
console.log(formattedDate); // Output: 1st Jan
<script src="https://unpkg.com/[email protected]/build/global/luxon.js"></script>