Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

convertible-js

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

convertible-js

Convert 12-hour time string to 24-hour time and vice versa with flexible formatting.

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

convertible-js :clock1:

dependencies Status npm version License: MIT

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

Docs

convertTime(input, options)

Converts 12-hour time string to 24-hour time and vice versa.

Arguments
NameTypeDescription
inputstringtime to convert or format
options (optional)Objectoptions object for converting and formatting
Options (Optional)

convertTo: Optional. The time type to convert to. Can only be either '12-hour' or '24-hour'

format: Optional. The desired time format.

UnitPatternResult examples
Hour [1-12]h1, 2, ..., 11, 12
hh01, 02, ..., 11, 12
Hour [1-23]H0, 1, 2, ..., 23
HH00, 01, 02, ..., 23
Minutem0, 1, ..., 59
mm00, 01, ..., 59
AM, PMaam, pm
AAM, PM
Returns ( string | undefined )

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.

Usage
// 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'

License

MIT © Ana Liza Pandac

Keywords

FAQs

Package last updated on 02 Sep 2019

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc