Posts

Showing posts with the label Time Converstion

TimeConversion in 24 hour format

Image
Given a time in -hour AM/PM format, convert it to military (24-hour) time. Note: - 12:00:00AM on a 12-hour clock is 00:00:00 on a 24-hour clock. - 12:00:00PM on a 12-hour clock is 12:00:00 on a 24-hour clock. function   convertionTime ( time ) {   const PMTime =   time . toString (). search ( "PM" )     const AmTime =   time . toString (). search ( "AM" )     let timeString =   time . split ( ":" )   if ( PMTime !== - 1 ) {     if ( Number ( timeString [ 0 ]) < 12 ){     timeString [ 0 ] = Number ( timeString [ 0 ]) + 12     }   } else if ( AmTime !== - 1 ){     if ( Number ( timeString [ 0 ]) == 12 ){     timeString [ 0 ] = "00"     }   }   const joinedString = timeString . join ( ":" ). slice ( 0 , 8 )   return joinedString } const HourFormat =   convertionTime ( "01:05:45PM" ) console . log ( HourFormat )