npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@rockyli/timestamp

v2.0.0

Published

A lightweight Javascript library to convert between timestamp and datetime string

Downloads

6

Readme

node-timestamp

Build Status Download Stats

A lightweight Javascript library to convert between timestamp and datetime string.

Installation

To install timestamp library, use npm:

npm install @rockyli/timestamp

Usage

const timestamp = require('@rockyli/timestamp');

timestamp.current(); // return current timestamp in seconds
timestamp.current('ms'); // return current timestamp in milliseconds

timestamp.fromDate(new Date()); // return current timestamp in seconds
timestamp.fromDate(new Date(), { unit: 'ms' }); // return current timestamp in seconds

timestamp.fromDatetimeString('2019-03-13', { format: 'YYYY-MM-DD' }); // return timestamp of 2019-03-13 00:00:00 in seconds
timestamp.fromDatetimeString('2019-03-13T12:34:00+08:00', { unit: 'ms' }); // return timestamp of 2019-03-13 12:34:00 in milliseconds

timestamp.toDate(1556766507); // return Date object of 2019-05-02T11:08:27.000+08:00

timestamp.toDatetimeString(1552406400); // return datetime string of 2019-03-13T00:00:00.000+08:00
timestamp.toDatetimeString(1552406400, { format: 'YYYY-MM-DD' }); // return datetime string of 2019-03-13
timestamp.toDatetimeString(1552406400, { format: 'HH:ss' }); // return datetime string of 00:00

API

  • current(unit)

    • unit - current timestamp unit. (default: 's') [OPTIONAL]
  • fromDate(date, options)

    • date - datet object to convert
    • options.unit - datetime string unit. (default: 's') [OPTIONAL]
  • fromDatetimeString(datetimeString, options)

    • datetimeString - datetime string to convert
    • options.format - datetime string format. (default: 'YYYY-MM-DDTHH:mm:ss.SSSZ') [OPTIONAL]
    • options.timezone - datetime string timezone. (default: 'Asia/Shanghai') [OPTIONAL]
    • options.unit - datetime string unit. (default: 's') [OPTIONAL]
  • toDate(timestamp, options)

    • timestamp - timestamp to convert
    • options.unit - datetime string unit. (default: 's') [OPTIONAL]
  • toDatetimeString(timestamp, options)

    • timestamp - timestamp to convert
    • options.format - datetime string format. (default: 'YYYY-MM-DDTHH:mm:ss.SSSZ') [OPTIONAL]
    • options.timezone - datetime string timezone. (default: 'Asia/Shanghai') [OPTIONAL]
    • options.unit - datetime string unit. (default: 's') [OPTIONAL]

Tests

npm install
npm run test

LICENSE

node-timestamp is licensed under the MIT license.