How can i convert linux "date +%s" output to a more readable format in bash script
Here is the script:
#!/bin/bash
i="0"
s开发者_StackOverflowtartTime=`date -u +%s`
startTime=$[$startTime+$1+5]
echo ""
echo "##################"
echo "LAUNCHING REQUESTS"
echo " COUNT: $1 "
echo " DELAY: 1 "
echo " EXECUTION: $startTime "
echo "##################"
echo ""
while [ $1 -gt "$i" ]
do
i=$[$i+1]
php avtestTimed.php $1 $2 $startTime &
echo "QUEUEING REQUEST $i"
sleep 1
done
so i want to convert $startTime into a UTC format
Try:
date -d @$(($startTime-$1-5))
if you want to decode the first state of $startTime variable, or this:
date -d @$startTime
and, you can add -u
argument to get the UTC time... %)
read the man date
What format are you looking for? Simply executing date with -u Will give you a readable output format of UTC time, ie:
# date -u
Tue Nov 30 15:35:12 UTC 2010
You can use -d
to pass $startTime
back into date
for processing, just prefix it with @
so it is recognized as seconds since the epoch.
$ date -d @$startTime
Once you have that down you can change the output format. I would suggest looking at the man page or the info documentation of date
for that. For UTC output you would use
$ date -d @$startTime -u
I'd have another variable
startTimeHuman=$(date -u -R)
right next to where you set startTime. This way you'd have both variants, one for doing math, and one for humans to understand.
Got perl?
human_time=$(perl -e 'print scalar gmtime(shift)' $startTime)
精彩评论