Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sungwoncho/convert-time
Convert a string between 12-hour time and 24-hour time
https://github.com/sungwoncho/convert-time
time
Last synced: about 2 months ago
JSON representation
Convert a string between 12-hour time and 24-hour time
- Host: GitHub
- URL: https://github.com/sungwoncho/convert-time
- Owner: sungwoncho
- License: mit
- Created: 2015-11-06T23:04:58.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-03-23T22:07:08.000Z (almost 8 years ago)
- Last Synced: 2024-11-01T18:51:45.720Z (2 months ago)
- Topics: time
- Language: JavaScript
- Homepage:
- Size: 7.81 KB
- Stars: 6
- Watchers: 3
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Convert-time
[![Build Status](https://travis-ci.org/sungwoncho/convert-time.svg?branch=master)](https://travis-ci.org/sungwoncho/convert-time)
Convert a string between 12-hour time and 24-hour time with customizable format.
## Install
npm install convert-time
## Usage
```js
var convertTime = require('convert-time');convertTime('2pm');
// => '14:00'
convertTime('2a.m.');
// => '2:00'
convertTime('15:00');
// => '3:00 pm'
convertTime('2:00', 'HH : mm A');
// => '14 : 00 PM'
```## API
### convertTime(time, [format])
If `time` is in 12-hour time, convert it to 24-hour time, and vice-versa. Use
`format` to customize the output, if provided.`time` is a string representing time in either 12-hour or 24-hour format.
`format` is an optional string argument to specify the output format. Acceptable
values are:* `hh` - Hour. It can be one or two digits.
* `HH` - Hour. It is always two digits. If one digit, `0` is appended in
the front. (e.g. `3` becomes `03`)
* `mm` - Minute. It can be one or two digits.
* `MM` - Minute. It is always two digits. If one digit, `0` is appended in
the front. (e.g. `9` becomes `09`)
* `a` - Period. `am` or `pm`.
* `A` - Capitalized period. `AM` or `PM`.Default values for format are:
* `hh:MM` for 12-hour to 24-hour conversion.
* `hh:MM a` for 24-hour to 12-hour conversion.## License
MIT