Skip to content

Commit

Permalink
- Added timezone support in format method (#19)
Browse files Browse the repository at this point in the history
Co-authored-by: Marek Ulwański <mulwanski@trans.eu>
  • Loading branch information
ulwanski and Marek Ulwański committed Mar 17, 2023
1 parent 9e71a7f commit b581d1d
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 5,511 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Expand Up @@ -20,6 +20,7 @@
"linebreak-style": ["warn", "unix"],
"quotes": ["off"],
"semi": ["error", "always"],
"@typescript-eslint/no-explicit-any": ["off"]
"@typescript-eslint/no-explicit-any": ["off"],
"@typescript-eslint/no-inferrable-types": ["off"]
}
}
11 changes: 9 additions & 2 deletions README.md
Expand Up @@ -48,11 +48,11 @@ console.log(date.format("YY-MM-D HH:mm:ss.S"));
## Methods

### format()
Return the formatted date string in the given format.
Return the formatted date string in the given format, optionally converts to different timezone.

#### Syntax
```
format(format: string): string;
format(format: string, locales?: string | string[], timezoneName?: string): string;
```

#### Example
Expand All @@ -61,6 +61,13 @@ const date = new Date();
const formattedDate = date.format("YY-MM-D HH:mm:ss.S");
```

```typescript
const date = new Date("2022-04-18 15:30:00 +01:00");

// Convert time to Tokyo timezone
const formattedTime = date.format("YY-MM-D HH:mm:ss.S", "en-US", "Asia/Tokyo");
```

#### Accepted patterns:
| Pattern | Description | Example |
|:-------:|----------------------------------------------------------|:----------:|
Expand Down

0 comments on commit b581d1d

Please sign in to comment.