unixseconds
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

unixseconds

No nonsense / No Bullshit micro library to get CURRENT unix time in SECONDS.

Usage

Install

npm install unixseconds
const unixseconds = require("unixseconds");
unixseconds(); // Current unix time in seconds.

Details

  • Purpose of this is to standardize how timestamp is dealt with throughout all our softwares
  • Uses Math.trunc(Date.now() / 1000) internally.
    • Truncates instead of rounding, thus data lose.
    • Purpose is just to keep it simple
    • Has the same effect as using Zero-fill right shift but using Math.trunc is more readable and understandable.
      • Take a look by running
        // 1. Seconds with decimals representing milliseconds
        // 2. Seconds using Zero-fill right shift
        // 3. Seconds using Math.trunc
        console.log(Date.now() / 1000, Date.now() / 1000 >>> 0, Math.trunc(Date.now() / 1000))
  • Uses common JS, so suitable for node or frontends with suitable build tools.
  • Might not work on IE if Date.now is not available

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i unixseconds

Weekly Downloads

1

Version

0.1.1

License

MIT

Unpacked Size

2.88 kB

Total Files

5

Last publish

Collaborators

  • jaimeloeuf