I am trying to print out the time in AM / PM format with this code:
#!/bin/bash
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
--AMPM| --ampm)
while true;
do
#Time in AMPM format:
echo $(date +"%r")
sleep 1s;
clear;
done
esac
done
I get this: HH:MM:SS I want to get this: HH:MM
How can i alter the code to do so ? or why doesnt it work ?
If you are using at least bash
4.2, you don't even need date
:
printf '%(%I:%M %p)T\n'
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 love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With