Skip to content

GloryWong/iso-timestamp

Repository files navigation

GitHub License GitHub commit activity GitHub Actions Workflow Status GitHub Release GitHub Release Date GitHub Issues or Pull Requests GitHub watchers GitHub forks GitHub Repo stars NPM Version NPM Type Definitions NPM Downloads Node Current

iso-timestamp

Generate ISO 8601 timestamp: YYYYMMDDhhmmssSSS

Install

npm install iso-timestamp

or

yarn add iso-timestamp

or

pnpm add iso-timestamp

API

timestamp(options?) or timestamp(date, options?)

  • date: Custom date

  • options:

    • excludeTime: Exclude time, i.e. hour, minute and second. Default: false
    • excludeMillisecond: Exclude millisecond from time. Default: false
    • separator: Separator among elements of the timestamp. Default: ''
import timestamp from 'iso-timestamp'
// Or import { timestamp } from 'iso-timestamp'

timestamp()
// return current timestamp: 202408070101123

timestamp({ excludeMillisecond: true })
// return timestamp with millisecond excluded: 202408070101

timestamp({ excludeTime: true })
// return timestamp with time excluded: 20240807

timestamp(new Date('2050-03-04T12:03:04.123'), { excludeMillisecond: true })
// return timestamp with custom Date: 20500304120304

timestamp({ separator: '-', excludeTime: true })
// return timestamp with custom separator: 2024-08-07

Authors

👤 GloryWong

Show Your Support

Give a ⭐️ if this project helped you!