您可以立即致电:
momentLocaleData.firstDayOfWeek()
是否有可能在 Luxon 中获得相同的功能?
我担心,在最新版本 ( 1.3.3) 中,这是不可能的,因为文档指出:
基本国际化。Luxon 的代码中没有国际化的字符串;相反,它依赖于 Intl API 的主机实现。这包括非常方便的toLocaleString。大多数浏览器和最新版本的 Node 都支持这一点。
此外,使用 Luxon,您始终将星期一作为一周的第一天,如以下代码段所示:
// Luxon
const DateTime = luxon.DateTime;
console.log( DateTime.local().setLocale('fr-CA').startOf('week').toISO() );
// Moment.js
console.log( moment().locale('fr-ca').startOf('week').format() );Run Code Online (Sandbox Code Playgroud)
<script src="https://moment.github.io/luxon/global/luxon.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment-with-locales.min.js"></script>Run Code Online (Sandbox Code Playgroud)
请注意,文档中没有'week'参数startOf:
“设置”这个 DateTime 到一个时间单位的开始。
参数:
Run Code Online (Sandbox Code Playgroud)Name Type Attribute Description unit string The unit to go to the beginning of. Can be 'year', 'month', 'day', 'hour', 'minute', 'second', or 'millisecond'.