我正在将打字稿应用程序转换为使用Luxon而不是用于DateTime处理的时刻,并且不确定如何使用Luxon的内置功能(或可配置的选项)作为两个字母返回一周中的一天。
片刻:
momment()。格式('mm/dd/y')
应返回 '04/tu/2022'
。
卢克森:
dateTime.now()。toformat('mm/ccc/yyyy')
,但这给了我 '04/tue/2022'
,这不适合所需的后端数据格式。
我可以设置一个选项参数来指定一周中返回的字母数量吗?还是另一种方法?
这是我发现的一个示例,可让您使用选项指定2位数量的日子和月份...
dateTime.now()。tolocalestring({day:'二维',月份:'2位数','2位数',年:'numeric'})
=> 05/10/2022
I am converting a typescript app to use Luxon instead of Moment for datetime processing and am not sure how to use Luxon's built-in features (or configurable options) to return the day of week as two letters.
Moment:
moment().format('MM/dd/y')
should return '04/Tu/2022'
.
Luxon:
DateTime.now().toFormat('MM/ccc/yyyy')
but that gives me '04/Tue/2022'
, which does not fit the required backend data format.
Is there an options parameter I can set to specify the number of letters to return for the day of week string? Or another approach?
This is an example that I found that allows you to specify 2 digit day and month using options...
DateTime.now().toLocaleString({ day: '2-digit', month: '2-digit', year: 'numeric' })
=> 05/10/2022
发布评论
评论(1)
我担心与Luxon,令牌表仅列出
ccc
(每周的日,作为缩写本地化字符串),cccc
(一周中的一天,一天中的一天)作为一个毫不掩饰的本地化字符串),ccccc
(每周的一天,作为单个局部字母),它绘制可能的值('nrarch'
,'short '
,'long'
) intl.datetimeformat option 。可能的解决方法是使用自定义功能,并仅获得一周中一天的前两个数字。
I fear that this is not possible "natively" with Luxon, Table of tokens lists only
ccc
(day of the week, as an abbreviate localized string),cccc
(day of the week, as an unabbreviated localized string),ccccc
(day of the week, as a single localized letter) that maps exactly the possible values ('narrow'
,'short'
,'long'
) of weekday key of the Intl.DateTimeFormat option object.Possible workaround is to use custom function and get only first two digit of day of the week.