I'm trying to write a shell script that displays the time in am or pm rather than the way it is shown using date command. I'm not sure how I should go about doing this. I guess for starters, how do I extract the time from the date command to manipulate it? And how do I extract the number for the hour to manipulate it?
You can use below one to print time in AM and PM format up to minutes.
echo $(date +"%I:%M %p")
OutPut: 09:20 PM
or
echo $(date +"%r")
Output: 09:20:09 PM
or echo $(date +"%I %p")
Output: 09 PM
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