python - Bash: Read UTC timestamp from a file and transform to Local Time for different Target Timezones -


i have utc timestamps in file generated using bash date following:

'sat mar 15 01:30:01 utc 2014' 'sat mar 15 01:30:16 utc 2014' 'sat mar 15 02:00:01 utc 2014' 'sat mar 15 02:00:12 utc 2014' 

i need transform timestamps local time of different regions. e.g. convert first entry above hongkong time, second singapore , on. can generate offsets can added local time. offsets following:

2:00 -5:00  .  . 

one possible approach may parse date using python , add/subtract offset.

however i'm wondering if can preferably in bash date. i've tried increment/decrement date such as:

date -d 'sat mar 15 01:30:01 utc 2014 2 hours' 

however, above convert specified date system's date , add 2 hours, whereas need achieve particular target timezone , without having rely on specifying offsets manually.

i avoid offset approach , specify target timezone directly. example convert date hong kong time using gnu date:

$ tz='asia/hong_kong' date -d 'sat mar 15 01:30:01 utc 2014' sat mar 15 09:30:01 hkt 2014 

tz time zone variable. -d option date tells read time specified string.

if don't specify tz, computer's default time zone:

$ date -d 'sat mar 15 01:30:01 utc 2014' fri mar 14 18:30:01 pdt 2014 

a list of timezones country here.

this approach not applicable mac osx (bsd) version of date -d else.


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -