1. unix-timestamp
Tiny library to create and manipulate Unix timestamps
unix-timestamp
Package: unix-timestamp
Created by: attentif
Last modified: Mon, 04 Dec 2023 13:10:02 GMT
Version: 1.0.4
License: BSD-3-Clause
Downloads: 128,470
Repository: https://github.com/attentif/unix-timestamp-js

Install

npm install unix-timestamp
yarn add unix-timestamp

unix-timestamp

CI npm

Tiny library to create and manipulate Unix timestamps in Javascript. (A Unix timestamp is the number of seconds elapsed since Unix epoch time, i.e. January 1 1970 00:00 UTC.)

Usage

 npm install unix-timestamp

Then:

 const timestamp = require('unix-timestamp');

Methods

  • .now([offset]) gives the current time, optionally applying an offset (see below)
  • .fromDate(dateOrString) gives the time from a Javascript Date object or an ISO 8601 date string
  • .toDate(time) correspondingly gives the date from a timestamp
  • .add(time, offset) applies an offset to the given time
  • .duration(offset) gives the offset timestamp for the given offset string

An offset can be either a number (unit: seconds) or a string with format [+|-] [{years}y] [{months}M] [{weeks}w] [{days}d] [{hours}h] [{minutes}m] [{seconds}s] [{milliseconds}ms] (for example -30s).

The actual values (in seconds) used for each unit of time in an offset string are exposed by properties .Millisecond, .Second, .Minute, .Hour, .Day, .Week, .Month (i.e. mean Gregorian month) and .Year.

About rounding

By default timestamps include decimals (fractions of a second). You can set the lib to round all returned timestamps to the second with timestamp.round = true.

Contributing

npm test runs the tests with Mocha.

npm run test-cover runs the tests and outputs coverage stats with Istanbul.

npm run license updates license information with source-licenser.

The code follows the Semi-Standard style.

License

BSD-3-Clause

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin