I have to calculate the date epoch time from a GMT timestamp, but I'm locally not in that timezone. My current local time is CEST.
So when I try to calculate the epoch time with
date -d "2017-08-05 10:10:10" "+%s"
I get
1501927810
But the given time is a GMT, and should therefore result in
1501927810
I was trying to manually add the difference of hours between the local time and the GMT with
date -d "2017-08-05 10:10:10 +2 hours" "+%F %T"
But that gives me
2017-08-05 11:10:10
why is there only +1 hour added!?
You can tell date
to use GMT timezone by setting the environment variable TZ
:
$ TZ=GMT date -d "2017-08-05 10:10:10" "+%s"
1501927810
Otherwise you would have to specify the date string as GMT (+0 hours, not 2):
$ date -d "2017-08-05 10:10:10 +0" "+%s"
1501927810
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加