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

react-datetime-module

v1.0.5

Published

An NPM Package to use date and time effectively in React

Downloads

8

Readme

React Datetime Module

Introduction

This package provides a set of functions that can be used in various JavaScript environments such as React, Next.js, and Node.js for datetime-related operations.

Installation

npm i react-datetime-module

Import

import { getCurrentTime, getCurrentTimezone, distanceToNow } from 'react-datetime-module'
let timeRightNow = getCurrentTime("MONNAME DD, YYYY. hh:mm:ss a");
{/*In JSX*/}
<h1>{getCurrentTime("HH:mm:ss")}</h1>{/*HH gives you 24-hr format*/}

Functions

1. getCurrentTime()

Returns the current time formatted according to the specified format.

Usage:

let myFormat = getCurrentTime("MONNAME DD, YYYY. hh:mm:ss a");
console.log(myFormat); // Example output: Mar 31, 2024. 06:56:01 pm

Function Options for getCurrentTime()

The getCurrentTime function uses the following options to format the time string:

  • 'YYYY': This option will be replaced with the full year (e.g., 2024).
  • 'YY': This option will be replaced with the last two digits of the year (e.g., 24 for the year 2024).
  • 'MM': This option will be replaced with the month (e.g., 03 for March).
  • 'DD': This option will be replaced with the day of the month (e.g., 26).
  • 'hh': This option will be replaced with the hour in 12-hour format (e.g., 05 for 5 am or 05 for 5 pm).
  • 'HH': This option will be replaced with the hour in 24-hour format (e.g., 17 for 5 pm).
  • 'mm': This option will be replaced with the minutes (e.g., 55).
  • 'ss': This option will be replaced with the seconds (e.g., 51).
  • 'a': This option will be replaced with 'am' or 'pm' depending on whether the hour is before or after noon.
  • 'MONTHNAME': This option will be replaced with the full name of the month (e.g., March).
  • 'MONNAME': This option will be replaced with the short name of the month (e.g., Mar).

These options allow you to customize the format of the time string that the getCurrentTime function returns. For example, if you use the format 'MONNAME DD, YYYY. hh:mm:ss a', the function will return a string like 'Mar 26, 2024. 05:55:51 am'.

2. distanceToNow()

Calculates the distance from the current time to the target time.

Usage:

console.log(distanceToNow('Mar 26, 2034 17:55:51', { addSuffix: true, includeSeconds: true })); // Example output: about 9 years from now

3. convertToUnixTimestamp()

Converts a given time to a Unix timestamp.

Usage:

console.log(convertToUnixTimestamp()); // Example output: 1711891857 [No argument gives you the current timestamp]

4. convertFromUnixTimestamp()

Converts a Unix timestamp to a formatted date string.

Usage:

console.log(convertFromUnixTimestamp(1711461716, 'MONTHNAME DD, YYYY hh:mm:ss a')); // Output: March 26, 2024 07:31:56 pm [You can mention the output format]

5. getCurrentTimezone()

Get the current timezone of the user.

Usage:

console.log(getCurrentTimezone()); // Example output: Asia/Calcutta (UTC+5.5)

Testing

To test these functions, refer to the testIndex.js file in the same folder.

Issues and Support

For questions, bug reports, or feature requests, please raise an issue on GitHub.

Connect with the Developer

Connect with me on LinkedIn for any further assistance or collaboration.

Feel free to use this in your project!