Thursday, May 3, 2012

HowTo: Get Current Time In Shell Script

How do I get current server time in shell script?

You can use the date command as follows to print current time only:
date +"%T"
Sample outputs:
16:33:22
To store time to a shell variable, enter:
ow=$(date +"%T")
echo "Current time : $now"

See also:

man date

No comments:

Post a Comment