Skip to content

Micro library for converting hours between 12-hour and 24-hour formats

License

Notifications You must be signed in to change notification settings

jimf/hour-convert

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hour-convert

Micro library for converting hours between 12-hour and 24-hour formats.

npm Version Build Status Test Coverage Dependency Status

Installation

Install using npm:

$ npm install hour-convert

Usage

var hourConvert = require('hour-convert');

// 24-hour to 12-hour format
hourConvert.to12Hour(0);   // { hour: 12, meridiem: 'am' }
hourConvert.to12Hour(6);   // { hour: 6, meridiem: 'am' }
hourConvert.to12Hour(12);  // { hour: 12, meridiem: 'pm' }
hourConvert.to12Hour(18);  // { hour: 6, meridiem: 'pm' }

// 12-hour to 24-hour format
hourConvert.to24Hour({ hour: 12, meridiem: 'am' });  // 0
hourConvert.to24Hour({ hour:  6, meridiem: 'am' });  // 6
hourConvert.to24Hour({ hour: 12, meridiem: 'pm' });  // 12
hourConvert.to24Hour({ hour:  6, meridiem: 'pm' });  // 18

Note: The spelling "meridian" is also supported/returned for backwards compatibility.

License

MIT

About

Micro library for converting hours between 12-hour and 24-hour formats

Resources

License

Stars

Watchers

Forks

Packages

No packages published