I want to format 12-hour time to 24-hour time using format() function from date-fns library, however, I got an error.
This is the code:
import {format} from 'date-fns'
const convertFrom12HourTimeTo24HourTime = (twelveHourTime: TwelveHourTime) => {
const { hour, minute, meridiem } = twelveHourTime;
const toFormatTime = new Date(`${hour}:${minute} ${meridiem}`);
const formattedTime = format(toFormatTime, 'HH:mm');
console.log(formattedTime);
}