Bash time format HH:MM in 12 hour format AM/PM Bash time format HH:MM in 12 hour format AM/PM shell shell

Bash time format HH:MM in 12 hour format AM/PM


Format date output:

date +"%I:%M %p"date +"%I:%M %P"

Where:

%I     hour (01..12)%M     minute (00..59)%p     locale's equivalent of either AM or PM; blank if not known%P     like %p, but lower case


If you are using at least bash 4.2, you don't even need date:

printf '%(%I:%M %p)T\n'


You can just replace the following line

echo $(date +"%r")

with

echo $(date +"%r" | sed -e 's/\([0-9][0-9]:[0-9][0-9]\):[0-9][0-9]/\1/')