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

1.0.4 • Public • Published

timestamp-timer

timestamp-timer Logo

A Custom Hook for Timer in react.

Installation

You can install timestamp-timer using npm:

npm install timestamp-timer

Example:

import React from 'react';
import useTimestampTimer from 'timestamp-timer';

function MyComponent() {
  const initialTimestamp = new Date().getTime(); // Replace this with your timestamp logic
  const elapsedTime = useTimestampTimer(initialTimestamp);

  return (
    <div>
      Elapsed time: {elapsedTime} milliseconds
    </div>
  );
}

export default MyComponent;

Hook will actually return the in milliseconds u can convert it to any format u want an example:

    const formatTime = (milliseconds) => {
      const seconds = Math.floor(milliseconds / 1000);
      const minutes = Math.floor(seconds / 60);
      const hours = Math.floor(minutes / 60);
      const days = Math.floor(hours / 24);
  
      return `${days}:${hours % 24}:${minutes % 60}:${seconds % 60}`;
    };

Package Sidebar

Install

npm i timestamp-timer

Weekly Downloads

2

Version

1.0.4

License

MIT

Unpacked Size

2.64 kB

Total Files

4

Last publish

Collaborators

  • pranavbharadwaj007