You can use a ternary operator inside the date to set a conditional format.
date($format = (date(G) > 11) ? 'h:i \ص' : 'h:i \م');
or for am/pm
date($format = (date(G) > 11) ? 'h:i \p\m' : 'h:i \a\m');
You can set the format different than h:i but this will show 05:40 pm
for 17:40 or 05:40 am
for 05:40. It looks for date(G) which is the hours in 0-23 format. If date(G) is greater than 11, it uses the first format, else uses the second format.
Here is a fork of your code http://ideone.com/BobelH