
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
convertible-js
Advanced tools
Convert 12-hour time string to 24-hour time and vice versa with flexible formatting.
Convert 12-hour time string to 24-hour time and vice versa with flexible formatting.
The library is available as an npm package. To install the package run:
npm install convertible-js --save
# or with yarn
yarn add convertible-js
Converts 12-hour time string to 24-hour time and vice versa.
Name | Type | Description |
---|---|---|
input | string | time to convert or format |
options (optional) | Object | options object for converting and formatting |
convertTo
: Optional. The time type to convert to. Can only be either '12-hour'
or '24-hour'
format
: Optional. The desired time format.
Unit | Pattern | Result examples |
---|---|---|
Hour [1-12] | h | 1, 2, ..., 11, 12 |
hh | 01, 02, ..., 11, 12 | |
Hour [1-23] | H | 0, 1, 2, ..., 23 |
HH | 00, 01, 02, ..., 23 | |
Minute | m | 0, 1, ..., 59 |
mm | 00, 01, ..., 59 | |
AM, PM | a | am, pm |
A | AM, PM |
string
- By default, it returns the opposite format of the given time (12-hour
to 24-hour
) unless convertTo
is specified in the second argument object.
undefined
- If arguments provided are invalid or if an error occured while rounding the time. The library will not throw any error.
// CommonJS
// var convertTime = require('convertible-js').default;
// ES2015
import convertTime from 'convertible-js';
convertTime('12:04am'); // => '00:04'
convertTime('10:00am'); // => '10:00'
convertTime('2pm'); // => '14:00'
convertTime('1am'); // => '01:00'
convertTime('10:00:50am'); // => '10:00:50'
convertTime('10:00:54pm'); // => '22:00:54'
convertTime('10:00pm'); // => '22:00'
convertTime('12:06:34PM'); // => '12:06:34'
convertTime('12:06:34AM'); // => '00:06:34'
convertTime('00:00'); // => '12:00 AM'
convertTime('10:00'); // => '10:00 AM'
convertTime('22:00:54'); // => '10:00:54 PM'
convertTime('23:59:54'); // => '11:59:54 PM'
// Using `convertTo`
convertTime('00:00', { convertTo: '24-hour' }); // => '00:00', since it's already in 24-hour
convertTime('00:01', { convertTo: '12-hour' }); // => '12:01 AM'
// Using `format`
convertTime('10:34pm', { convertTo: '24-hour', format: 'HH:mm' }); // => '22:34'
convertTime('10:34pm', { convertTo: '12-hour', format: 'HH:mm A' }); // => '10:34 PM'
MIT © Ana Liza Pandac
FAQs
Convert 12-hour time string to 24-hour time and vice versa with flexible formatting.
The npm package convertible-js receives a total of 0 weekly downloads. As such, convertible-js popularity was classified as not popular.
We found that convertible-js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.