You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// => Fri Aug 23 2025 14:30:00 GMT+0500 (New_York timeZone is ignored)
171
171
```
172
172
173
+
:::warning Important Difference from format()
174
+
The `parse()` function only accepts TimeZone objects and the "UTC" string for the `timeZone` option. Unlike `format()`, which supports both TimeZone objects and IANA timezone name strings, `parse()` does not support string type timezone names.
175
+
:::
176
+
173
177
For a complete list of all supported timezones with import examples, see [Supported Timezones](../timezones).
Additionally, since the `timezone` plugin has been integrated into the main library, the `formatTZ` function is now obsolete. Timezones are now imported as modules rather than using `IANA time zone names` (except for UTC timezone).
40
+
Additionally, since the `timezone` plugin has been integrated into the main library, the `formatTZ` function is now obsolete. In v4.0/4.1, timezones must be imported as TimeZone objects from timezone modules. IANA timezone name strings are not supported in this version (except for UTC timezone).
// => Wednesday, July 23, 2025 at 3:28:27.443 GMT-04:00
48
48
```
49
49
50
+
#### New in v4.2.0: Enhanced Timezone Support
51
+
52
+
In addition to TimeZone objects, the `format()` function now supports specifying timezones using IANA timezone name strings. This provides flexibility in how you work with timezones:
The third argument has been changed from `boolean` to `ParserOptions`. With `ParserOptions`, you can now specify timezone and locale settings. If you previously set the third argument to `true` to parse input in UTC timezone, you can achieve the same output as follows:
Import multiple timezones from a single module using named imports. This approach is recommended when working with multiple timezones as it provides better code organization.
28
+
29
+
```typescript
30
+
import { format } from'date-and-time';
31
+
import { Tokyo, New_York, London, Sydney } from'date-and-time/timezone';
32
+
33
+
const date =newDate();
34
+
35
+
format(date, 'YYYY-MM-DD HH:mm:ss', { timeZone: Tokyo }); // JST
format(date, 'YYYY-MM-DD HH:mm:ss', { timeZone: London }); // GMT/BST
38
+
format(date, 'YYYY-MM-DD HH:mm:ss', { timeZone: Sydney }); // AEDT/AEST
39
+
```
40
+
41
+
Both Method 1 and Method 2 provide the same functionality - they differ only in code organization.
42
+
43
+
### Method 3: IANA Timezone Name String
44
+
45
+
Functions that accept `FormatterOptions` (such as `format()` and `transform()`) allow you to specify timezones using IANA timezone name strings directly. This is the simplest approach.
**Important Note**: The `parse()` function does not support string type timezone names because it uses `ParserOptions` instead of `FormatterOptions`. Only TimeZone objects and the "UTC" string are supported for parsing.
0 commit comments