Skip to content

rish405/timestamp-to-iso

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

timestamp-to-iso

Tiny zero-dependency utility to convert timestamps to consistent UTC ISO-8601 strings.

Install

npm i timestamp-to-iso

Usage

import { toISO, isValidTimestamp } from 'timestamp-to-iso';

// Number in seconds
toISO(1577836800); // '2020-01-01T00:00:00.000Z'

// Number in milliseconds
toISO(1577836800000); // '2020-01-01T00:00:00.000Z'

// Date instance
toISO(new Date(1577836800000)); // '2020-01-01T00:00:00.000Z'

// Numeric or date-like strings
toISO('1577836800'); // '2020-01-01T00:00:00.000Z'
toISO('2020-01-01T00:00:00Z'); // '2020-01-01T00:00:00.000Z'

// Validate inputs
isValidTimestamp(1577836800); // true
isValidTimestamp('not-a-date'); // false

CJS

const { toISO, isValidTimestamp } = require('timestamp-to-iso');

API

  • toISO(input) — Converts number | string | Date to a UTC ISO-8601 string.
  • isValidTimestamp(input) — Returns true if input can be converted to a valid timestamp.

Notes

  • Numbers < 1e12 are treated as seconds, otherwise milliseconds.
  • All outputs are normalized to UTC using Date.toISOString().

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published