UTC Unix Timestamp Utility

1.0.6 · maintenance · verified Sun Apr 19

This package, `oc-get-unix-utc-timestamp` (v1.0.6), provides a straightforward utility function to retrieve the current Coordinated Universal Time (UTC) Unix timestamp. Published over four years ago, it maintains a stable, minimal footprint with zero external runtime dependencies. It ships with built-in TypeScript type definitions, enhancing development in typed environments. The primary function likely returns the timestamp in milliseconds since the Unix epoch (January 1, 1970, 00:00:00 UTC), aligning with JavaScript's native `Date.now()` behavior, which is a common source of confusion when "Unix timestamp" often refers to seconds. Its release cadence appears to be stable rather than actively developed, positioning it as a mature, low-maintenance utility. With weekly downloads around 19,000, it remains a used option for developers needing this specific functionality without additional overhead.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to import and use `getUnixUtcTimestamp` to retrieve the current UTC Unix timestamp in milliseconds and convert it to seconds or a Date object.

import { getUnixUtcTimestamp } from 'oc-get-unix-utc-timestamp';

// Get the current UTC Unix timestamp in milliseconds
const timestampMs: number = getUnixUtcTimestamp();
console.log(`Current UTC Unix timestamp (ms): ${timestampMs}`);

// To get the timestamp in seconds, divide by 1000 and floor
const timestampSeconds: number = Math.floor(timestampMs / 1000);
console.log(`Current UTC Unix timestamp (seconds): ${timestampSeconds}`);

// Example: Convert to a Date object
const dateFromTimestamp = new Date(timestampMs);
console.log(`Date object from timestamp: ${dateFromTimestamp.toUTCString()}`);

view raw JSON →