diff --git a/packages/@internationalized/date/docs/ZonedDateTime.mdx b/packages/@internationalized/date/docs/ZonedDateTime.mdx index 5b7e8ca9940..009b1fdb2e8 100644 --- a/packages/@internationalized/date/docs/ZonedDateTime.mdx +++ b/packages/@internationalized/date/docs/ZonedDateTime.mdx @@ -64,12 +64,14 @@ let date = parseAbsoluteToLocal('2021-11-07T07:45:00Z'); You can also create a `ZonedDateTime` using a `Date` object or epoch time (milliseconds) using one of the following functions: * – This function creates a `ZonedDateTime` from a `Date` object. A time zone identifier, e.g. `America/Los_Angeles`, must be passed, and the result will be converted into that time zone. +* – This function creates a `ZonedDateTime` from a `Date` object. The time zone identifier is automatically resolved from the current user’s environment, and the result is converted into that local time zone. * – This function creates a `ZonedDateTime` from a Unix epoch (e.g. `1688023843144`, representing milliseconds since 1970). A time zone identifier, e.g. `America/Los_Angeles`, must be provided, and the result will be converted into that time zone. ```tsx -import {fromDate, fromAbsolute} from '@internationalized/date'; +import {fromDate, fromDateToLocal, fromAbsolute} from '@internationalized/date'; let date = fromDate(new Date(), 'America/Los_Angeles'); +let date = fromDateToLocal(new Date()); let date = fromAbsolute(1688023843144, 'America/Los_Angeles'); ``` diff --git a/packages/@internationalized/date/src/conversion.ts b/packages/@internationalized/date/src/conversion.ts index 7b1ae398d1b..d34b256ae0e 100644 --- a/packages/@internationalized/date/src/conversion.ts +++ b/packages/@internationalized/date/src/conversion.ts @@ -197,6 +197,9 @@ export function fromDate(date: Date, timeZone: string): ZonedDateTime { return fromAbsolute(date.getTime(), timeZone); } +/** + * Takes a `Date` object and converts it to the time zone identifier for the current user. + */ export function fromDateToLocal(date: Date): ZonedDateTime { return fromDate(date, getLocalTimeZone()); } diff --git a/packages/@internationalized/date/src/index.ts b/packages/@internationalized/date/src/index.ts index 22e703f66f5..5d373c842f1 100644 --- a/packages/@internationalized/date/src/index.ts +++ b/packages/@internationalized/date/src/index.ts @@ -48,6 +48,7 @@ export { toTimeZone, toLocalTimeZone, fromDate, + fromDateToLocal, fromAbsolute } from './conversion'; export {