Get UTC time in seconds
You say you're using:
time.asctime(time.localtime(date_in_seconds_from_bash))
where date_in_seconds_from_bash
is presumably the output of date +%s
.
The time.localtime
function, as the name implies, gives you local time.
If you want UTC, use time.gmtime()
rather than time.localtime()
.
As JamesNoonan33's answer says, the output of date +%s
is timezone invariant, so date +%s
is exactly equivalent to date -u +%s
. It prints the number of seconds since the "epoch", which is 1970-01-01 00:00:00 UTC
. The output you show in your question is entirely consistent with that:
date -uThu Jul 3 07:28:20 UTC 2014date +%s1404372514 # 14 seconds after "date -u" commanddate -u +%s1404372515 # 15 seconds after "date -u" command