https://github.com/atayahmet/sec-to-format
Convert unix timestamp seconds to readable time format.
https://github.com/atayahmet/sec-to-format
human-readable-formats second-formatter seconds-to-hms time-converter time-format
Last synced: about 2 months ago
JSON representation
Convert unix timestamp seconds to readable time format.
- Host: GitHub
- URL: https://github.com/atayahmet/sec-to-format
- Owner: atayahmet
- License: mit
- Created: 2020-06-27T09:12:01.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-11-17T07:38:14.000Z (over 5 years ago)
- Last Synced: 2025-09-07T04:22:58.984Z (10 months ago)
- Topics: human-readable-formats, second-formatter, seconds-to-hms, time-converter, time-format
- Language: TypeScript
- Homepage:
- Size: 3.91 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- License: LICENSE
Awesome Lists containing this project
README
# Convert Seconds to Readable Format
[](https://badge.fury.io/js/sec-to-format) [](https://travis-ci.org/atayahmet/sec-to-format)
```sh
$ npm i sec-to-format --save
```
## Usage
```ts
import secToFormat from 'sec-to-format';
```
```ts
secToFormat(3601, '%H hour %s sec');
// 1 hour 1 sec
```
```ts
secToFormat(90643, '%D day %H hour %m minutes %s secs');
// 1 day 1 hour 10 minutes 43 secs
```
```ts
secToFormat(90643, '%D day %H:%m:%s');
// 1 day 1:10:43
```
## Setters
You can manipulate outputs by adding setter to the units.
```ts
const setters = {
'%H': hour => (hour < 10 ? `0${hour}` : hour),
'%m': min => (min < 10 ? `0${min}` : min),
};
secToFormat(7300, '%H:%m:%s');
// 2:1:40
secToFormat(7300, '%H:%m:%s', { setters });
// 02:01:40
```
## Unit Table
| Unit | Description |
| ---- | ----------- |
| %s | Second |
| %m | Minute |
| %H | Hour |
| %D | Day |
| %W | Week |
| %MM | Month |
| %Y | Year |
## Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
## License
[MIT](https://choosealicense.com/licenses/mit/)