简体   繁体   English

如何使用 Luxon 格式化日期?

[英]How to format a Date with Luxon?

With moment.js, you can format a date this way:使用 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>

How to do the same thing with Luxon?如何用 Luxon 做同样的事情? I've tried:我试过了:

 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

Source: https://github.com/moment/luxon/blob/master/docs/formatting.md来源: https : //github.com/moment/luxon/blob/master/docs/formatting.md

You can read more about the possible formats here: https://github.com/moment/luxon/blob/master/docs/formatting.md#the-basics您可以在此处阅读有关可能格式的更多信息: https : //github.com/moment/luxon/blob/master/docs/formatting.md#the-basics

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM