Perl – Converting the Time from 24 hr to 12 hr Format

Below is a Perl script that demonstrates how to appropriately convert the current time from 24 hr format to 12 hr format. The ‘convertToTwelveHr’ subroutine does all the work here. The 24 hr input value is passed into the subroutine and a two-element list containing the 12 hr value equivalent and a string of either ‘AM’ or ‘PM’ is returned.

Perl script that converts the time from 24 hr to 12 hr format

Perl script that converts the time from 24 hr to 12 hr format

Output:
Perl script output - 24 hr to 12 hr time conversion

This entry was posted in Perl, Programming Languages, Technology and tagged , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


four × = 12