我有以下 Javascript/Typescript 代码将字符串转换为 Luxon DateTime:
import { DateTime } from 'luxon';
const x = '2023-10-27T01:00:57.830+00:00'
const y = DateTime.fromFormat(x, 'yyyy-MM-dd');
console.log('y = ', y)
这会产生以下输出:
y = DateTime {
ts: 1698282057830,
_zone: SystemZone {},
loc: Locale {
locale: 'en-US',
numberingSystem: null,
outputCalendar: null,
intl: 'en-US',
weekdaysCache: { format: {}, standalone: {} },
monthsCache: { format: {}, standalone: {} },
meridiemCache: null,
eraCache: {},
specifiedLocale: null,
fastNumbersCached: null
},
invalid: Invalid {
reason: 'unparsable',
explanation: `the input "2023-10-27T01:00:57.830+00:00" can't be parsed as format yyyy-MM-dd`
},
weekData: null,
c: null,
o: null,
isLuxonDateTime: true
}
如何正确转换这个对象?
尝试使用
fromISO
方法。
import { DateTime } from 'luxon';
const x = '2023-10-27T01:00:57.830+00:00';
const y = DateTime.fromISO(x);