https://github.com/hedyhli/deno-datefmt
Unambiguous Golang-style date formatting library for Deno.
https://github.com/hedyhli/deno-datefmt
deno library typescript
Last synced: 6 months ago
JSON representation
Unambiguous Golang-style date formatting library for Deno.
- Host: GitHub
- URL: https://github.com/hedyhli/deno-datefmt
- Owner: hedyhli
- License: mit
- Created: 2024-05-16T13:38:51.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-20T08:33:42.000Z (10 months ago)
- Last Synced: 2025-02-10T15:50:43.322Z (8 months ago)
- Topics: deno, library, typescript
- Language: TypeScript
- Homepage: https://deno.land/x/datefmt
- Size: 28.3 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# datefmt
[](https://github.com/hedyhli/deno-datefmt/actions/workflows/deno.yml)
```js
import datefmt from "https://deno.land/x/datefmt/mod.ts"datefmt(new Date(1999, 5, 4), "[JAN]. [2nd], [2006]")
=> "MAR. 4th, 1999"
```- Similar to Golang's date(time) formats, but delimiters around format
specifiers are required. This makes formatting less ambiguous.
- 'nth' day formats are supported
- All forms of capitalization and zero-padding are both supported.The default delimiters are `[]`.
Delimiters can optionally be the same character.
```js
// Use single quote for both start and end delim
datefmt(date, "'2006' 'January'", true, "'")// Use < for start, and | for the end delim.
datefmt(date, "<2006| `"A[]B"`
- `A[[]B` => `"A[B"`
- `A[]]B` => `"A]B"`If delimiters are the same character, where `delim = "."`:
- `A.B` => `A.B`
- `A..B` => `A..B`
- `A...B` => `A.B`## Supported format specifiers
The standard date used is `Monday, January 2nd 03:04:05 PM 2006`
Tip for memorising: `01/02 03:04:05 2006 (PM) (Monday)`
Use any of the following format specifiers from within delimiters (by default,
`[]`), and they will be replaced with the corresponding value from the Date
object.Date
- 2006, 06, 6
- 01, 1
- Jan, jan, JAN, January, january, JANUARY
- 02, 2
- 2nd, 2NDDay
- Mon, mon, MON, Monday, monday, MONDAYTime
- PM, Pm, pm
- 3, 03
- 15 (24-hour time), 015
- 4, 04
- 5, 05Note, `"015"` is a special format for both 24-houur time and zero-padded. I.e.,
if the time is 9 AM, "15" and "3" both gives "9", whereas "015" and "03" both
gives "09".