The code I posted above uses a 24 hour clock. To convert that to a 12 hour clock you can use the following function:
byte hours24To12(byte hours){
if( hours == 0 )
return 12; // 12 midnight
else if( hours > 12)
return hours - 12 ;
else
return hours ;
}
Determining AM/PM is easier, if the 24 hour value is < 12 its AM , otherwise its PM