本文整理匯總了TypeScript中luxon.DateTime.fromJSDate方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript DateTime.fromJSDate方法的具體用法?TypeScript DateTime.fromJSDate怎麽用?TypeScript DateTime.fromJSDate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類luxon.DateTime
的用法示例。
在下文中一共展示了DateTime.fromJSDate方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: convertDate
function convertDate(date: string | Date): DateTime {
if (typeof date === 'string') {
return DateTime.fromISO(date);
} else {
return DateTime.fromJSDate(date);
}
}
示例2: toDateTime
export function toDateTime(date: Date, calendar: Calendar): LuxonDateTime {
if (!(calendar instanceof Calendar)) {
throw new Error('must supply a Calendar instance')
}
return LuxonDateTime.fromJSDate(date, {
zone: calendar.dateEnv.timeZone,
locale: calendar.dateEnv.locale.codes[0]
})
}
示例3: rezonedDate
public rezonedDate () {
if (this.isUTC) {
return this.date
}
try {
const datetime = DateTime
.fromJSDate(this.date)
const rezoned = datetime.setZone(this.tzid!, { keepLocalTime: true })
return rezoned.toJSDate()
} catch (e) {
if (e instanceof TypeError) {
console.error('Using TZID without Luxon available is unsupported. Returned times are in UTC, not the requested time zone')
}
return this.date
}
}