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


But the given time is a GMT, and should therefore result in


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"

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"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.