Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing shells script to display time in am or pm notation

Tags:

bash

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?

like image 631
zyxxwyz Avatar asked Feb 24 '13 20:02

zyxxwyz


1 Answers

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

like image 126
Venkat Avatar answered Sep 22 '22 12:09

Venkat