Micro library for converting hours between 12-hour and 24-hour formats.
Install using npm:
$ npm install hour-convert
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.
MIT