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

timestampconvertjs

v1.0.5

Published

A lightweight Javascript Library to easily convert UNIX timestamps to real world timezones

Downloads

168

Readme

TimestampConvert.js

A lightweight Javascript Library to easily convert UNIX timestamps to JSON-based real world timezones

npm version

Installation

This module is part of the npm package registry, and can be easily installed to a Node.js project:

npm install timestampconvertjs --save-dev

Methods

There are a few methods offered by this library:

  • getTime()

    function getTime(twelveHourFormat, hourOffset, minuteOffset)

Returns an output object with the current time in GMT, with an optional hour and minute offset which can be used to convert to any time-zone in the world.

  • twelveHourFormat: A boolean - true if the time should be formatted in twelve-hour format, false otherwise

  • hourOffset (optional): The number of hours to offset from GMT or UTC (For example, EST New York Time would have hourOffset of -4)

  • minuteOffset (optional): The number of minutes to offset from GMT or UTC (Very uncommon, but for example, Kathmandu time is GMT+5:45 so hourOffset would be 5, and minuteOffset would be 45)

  • convert()

    function convert(unixTimestamp, twelveHourFormat, hourOffset, minuteOffset)

Returns an output object with the time specified by unixTimestamp in GMT, with an optional hour and minute offset which can be used to convert to any time-zone in the world.

  • Signature definitions are as described above, with the exception that unixTimestamp in milliseconds is given by the user

  • getLocalTime()

    function getLocalTime(twelveHourFormat)

Returns an output object with the current time in your timezone.

  • Signature definitions are as described above

  • convertToLocalTime()

    function getLocalTime(twelveHourFormat)

Returns an output object with the time specified by unixTimestamp in your timezone.

  • Signature definitions are as described above

Output Format

The output is formatted as a JS object as follows:

{ year: YEAR,
  monthName: MONTH-NAME,
  monthNumber: MONTH-NUMBER,
  dayOfTheWeekNumber: DAY-OF-THE-WEEK-NUMBER,
  dayOfTheWeek: DAY-OF-THE-WEEK-NAME,
  day: DAY-NUMBER,
  hours: HOURS,
  minutes: MINUTES,
  seconds: SECONDS,
  milliseconds: MILLISECONDS,
  period: AM/PM,
  formattedTime: HOUR:MINUTE:SECONDS.MILLISECONDS }

the 'period' attribute only appears when twelveHourFormat is set to true.

Usage Example

var ts = require('timestampconvertjs');
var customUnixTimestamp = 1451606400000; //Sunday, August 12, 2018 1:05:31 AM
//or var customUnixTimestamp = new Date().getTime(); (To get current time in GMT)

//getTime() usage
var currTime = ts.getTime(true, -4); //Returns NY time (4 hours behind GMT) in 12-hr format

//convert() usage
var convertedTime = ts.convert(customUnixTimestamp, false); //Returns converted GMT time in 24-hr format

//getLocalTime() usage
var currTimeLocal = ts.getLocalTime(true); //Returns current time in local timezone in 12-hr format

//convertToLocalTime() usage
var convertedTimeLocal = ts.convertToLocalTime(customUnixTimestamp, false); //Returns converted time in local timezone in 24-hr format