shell - Convert UTC time to GMT bash script -


i trying convert utc time gmt time in small script, doesn't work:

timestamputc=$(date +"%s") echo $timestamputc dates=$(date -d @$timestamputc) echo $dates  ## 2 hours difference between utc , gmt hours2=120  timestampgmt=$((timestamputc - hours2)) echo $timestampgmt  diff=$((timestamputc - timestampgmt)) echo $diff  dategmt=$(date -d @$timestampgmt) echo $dategmt 

the displayed result $dategmt same $dates.

thanks in advance.

error in script.

unix timestaps given in seconds.

hours2=120 means 120 seconds.

so 2 timestaps diverging 2 minutes, not 2 hours.

this code correct:

hours2=7200 

also claim having 2 hours between gmt , utc, i'm sure mean cet (central european time)

note: there nothing cet timestamp. it's normal unix timestamp displayed timezone offset. independently of world location, unix timestamp always, worldwide, same @ same instant.

you can replace code this

# timestamp 2 hours in future date2h=$(date -d "2 hours" +%s) 

which gives unix timestamp future. not current timestamp in cet. current cet timestamp same utc.

how time utc , cet? set environment variable tz before command.

$ tz=utc date mon aug 17 11:44:05 utc 2015 $ tz=cet date mon aug 17 13:44:05 cest 2015 $ tz=gmt date mon aug 17 11:44:05 gmt 2015 

but timestap same

$ tz=utc date +%s 1439812072 $ tz=cet date +%s 1439812072 $ tz=gmt date +%s 1439812072 

Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -