time-format-converter
v1.0.0
Published
A package to convert 24-hour time format to 12-hour format (AM/PM).
Maintainers
Readme
24-Hour to 12-Hour Time Format Converter
This package provides a function to convert time from 24-hour format to 12-hour format (AM/PM).
Installation
You can install the package via npm:
npm install time-format-converterUsage
After installing the package, you can use it by importing the function and passing a 24-hour time string (in HH:mm format) to it. The function will return the time in a 12-hour format with AM/PM.
Example:
const convertTo12HourFormat = require('time-format-converter');
// Example 1: Convert 14:30 (2:30 PM)
console.log(convertTo12HourFormat('14:30')); // "2:30 PM"
// Example 2: Convert 06:45 (6:45 AM)
console.log(convertTo12HourFormat('06:45')); // "6:45 AM"
// Example 3: Convert 00:30 (12:30 AM)
console.log(convertTo12HourFormat('00:30')); // "12:30 AM"
// Example 4: Convert 23:59 (11:59 PM)
console.log(convertTo12HourFormat('23:59')); // "11:59 PM"API
convertTo12HourFormat(time24)
- time24 (string): A time string in the 24-hour format (e.g.,
14:30). - Returns (string): The time converted to the 12-hour format with
AM/PM(e.g.,2:30 PM).
License
MIT License
