https://github.com/trevorblades/clock-time
⏱ Formats milliseconds or minutes and seconds as clock time
https://github.com/trevorblades/clock-time
clock format milliseconds minutes seconds time
Last synced: about 2 months ago
JSON representation
⏱ Formats milliseconds or minutes and seconds as clock time
- Host: GitHub
- URL: https://github.com/trevorblades/clock-time
- Owner: trevorblades
- License: mit
- Created: 2017-07-18T01:50:56.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2023-03-01T09:48:10.000Z (over 2 years ago)
- Last Synced: 2025-07-31T18:56:07.500Z (2 months ago)
- Topics: clock, format, milliseconds, minutes, seconds, time
- Language: TypeScript
- Homepage: https://npm.im/clock-time
- Size: 1.57 MB
- Stars: 10
- Watchers: 1
- Forks: 2
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Clock Time
[](https://github.com/trevorblades/clock-time/actions)
Formats milliseconds or minutes and seconds as clock time
## Installation
```shell
npm install clock-time
```## Usage
Import or `require` the package and pass milliseconds as a single argument to get nicely formatted clock time.
```js
import clockTime from 'clock-time'; // es6
const clockTime = require('clock-time'); // cjsclockTime(60 * 1000); // 1:00
```Or, pass the number of minutes as the first argument and the number of seconds as the second argument instead.
```js
clockTime(4, 20); // 4:20
```### `toClockParts`
Use the named export `toClockParts` to convert milliseconds to an object of minutes, zero-padded seconds, and total seconds. This can be useful when you want to use the parts of a clock time separately or in addition to the formatted string.
If the second argument to `toClockParts` is `true`, zero-padding on the returned `seconds` property will be disabled and `seconds` will be a number.
```js
import {toClockParts} from 'clock-time';const {
minutes, // 4
seconds, // 20
total // 260
} = toClockParts(260000);const formatted = `${minutes}:${seconds}`; // or clockTime(minutes, seconds)
```## License
[MIT](./LICENSE)