gpt4 book ai didi

javascript - 如何使用 Luxon 格式化日期?

转载 作者:行者123 更新时间:2023-12-04 00:54:05 27 4
gpt4 key购买 nike

使用 moment.js,您可以通过以下方式格式化日期:

const date = moment("2010-10-22T21:38:00");
const data = date.format("LL - LT")
console.log(data)
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.0/moment.min.js" integrity="sha512-Izh34nqeeR7/nwthfeE0SI3c8uhFSnqxV0sI9TvTcXiFJkMd6fB644O64BRq2P/LA/+7eRvCw4GmLsXksyTHBg==" crossorigin="anonymous"></script>

如何用 Luxon 做同样的事情?我试过了:

const date = luxon.DateTime.fromISO("2010-10-22T21:38:00" );
const data = luxon.DateTime.fromFormat(date, "DATETIME_SHORT")
// output => script error
<script src="https://cdn.jsdelivr.net/npm/luxon@1.25.0/build/global/luxon.min.js"></script>

最佳答案

const date = DateTime.fromISO("2010-10-22T21:38:00")
const humanReadable = date.toLocaleString(DateTime.DATETIME_MED);

console.log(humanReadable); // => October 22, 9:38 PM
来源: https://github.com/moment/luxon/blob/master/docs/formatting.md
您可以在此处阅读有关可能格式的更多信息: https://github.com/moment/luxon/blob/master/docs/formatting.md#the-basics

关于javascript - 如何使用 Luxon 格式化日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64064891/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com