Один час слишком много в форматировании даты с использованием даты (1)

230
JDS

Если я выполняю следующие команды в терминале

start=$(date +%s) # wait a few seconds … end=$(date +%s)  time=$(dc <<< "$end $start -p") echo "$time"  echo "$(date -jr $time +%H:%M:%S)" 

Я получаю странный вывод

10 # This is ok, I executed the second line ten seconds after the first one 01:00:10 # But here *** where does the one hour come from? 

Кто-нибудь может объяснить, откуда взялся наш (я использую Mac OS 10.8)?
И, если нет способа подавить это, как изменить выход или добиться того же самого?

0

1 ответ на вопрос

2
faffaffaff

date -jr takes a unix timestamp (number of seconds since midnight jan 1 1970 GMT) and converts it to the equivalent local time. I'm betting you're running in a timezone that is one hour ahead of GMT. Ten seconds after midnight jan 1 1970 in GMT is one hour and ten seconds after midnight jan 1 1970 in CET, for example.

If you use the "-u" switch, you'll get UTC time. So this might work for you:

date -jur 10 '+%H:%M:%S'