https://github.com/tal7aouy/f-duration
⚡️ Convert milliseconds to a standard duration string.
https://github.com/tal7aouy/f-duration
convert convert-timestamps milliseconds time
Last synced: 8 months ago
JSON representation
⚡️ Convert milliseconds to a standard duration string.
- Host: GitHub
- URL: https://github.com/tal7aouy/f-duration
- Owner: tal7aouy
- License: isc
- Created: 2022-03-27T22:36:47.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-03-27T22:39:54.000Z (over 3 years ago)
- Last Synced: 2025-01-29T12:48:12.937Z (8 months ago)
- Topics: convert, convert-timestamps, milliseconds, time
- Language: TypeScript
- Homepage:
- Size: 59.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
Convert a number in milliseconds to a standard duration string.
| Input :disappointed: | Value :joy: |
| -------------------- | ----------- |
| `999` | `'0:00'` |
| `1000` | `'0:01'` |
| `1000 * 60` | `'1:00'` |
| `1000 * 60 * 60` | `'1:00:00'` |## Install
Get it on [npm](https://www.npmjs.com/package/f-duration)
```bash
npm install f-durationta
```Get it on [yarn](https://yarnpkg.com/package/f-duration)
```bash
yarn add f-duration
```## Usage
```js
import format from "f-duration"format(ms: number, options?: IOption)
// anything under a second is rounded down to zero
format(999) // '0:00'// 1000 milliseconds is a second
format(1000) // '0:01'// 1999 rounds down to 0:01
format(1000 * 2 - 1) // '0:01'// 60 seconds is a minute
format(1000 * 60) // '1:00'// 59 seconds looks like this
format(1000 * 60 - 1) // '0:59'// 60 minutes is an hour
format(1000 * 60 * 60) // '1:00:00'// 59 minutes and 59 seconds looks like this
format(1000 * 60 * 60 - 1) // '59:59'// 24 hours is a day
format(1000 * 60 * 60 * 24) // '1:00:00:00'// 23 hours, 59 minutes, and 59 seconds looks like this
format(1000 * 60 * 60 * 24 - 1) // '23:59:59'// 365 days looks like this (not bothering with years)
format(1000 * 60 * 60 * 24 * 365) // '365:00:00:00'// anything under a second is rounded down to zero
format(-999) // '0:00'// 1000 milliseconds is a second
format(-1000) // '-0:01'// 365 days looks like this (not bothering with years)
format(-1000 * 60 * 60 * 24 * 365) // '-365:00:00:00'// with `leading` option, formatting looks like this
format(1000 * 60, { leading: true }) // '01:00'
format(1000 * 60 - 1, { leading: true }) // '00:59'
format(1000 * 60 * 60, { leading: true }) // '01:00:00'
```## Contributing
Contributions welcome! Please read the [contributing guidelines](CONTRIBUTING.md) first.
## Default Options
| Name | Type | Default | Description |
| --------- | --------- | ------- | ----------------------------------------------------------------------- |
| `leading` | `boolean` | `false` | leading zero eg:(format(1000,{leading:true})) (00:01) instead of (0:01) |---
[MIT License](LICENSE)