1

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!?

4

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

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.