0

I have a script that reads files with linux timestamps and I'd like to convert them to human format while keeping the timezone offsets.

Script:

[..]
UPTIME=$(cut -d" " -f1 < /proc/uptime)
SECONDS=$(date +%s)
date -d"70-1-1 + $SECONDS sec - $UPTIME sec + $TIMESTAMP sec "   +"%d/%m/%Y %T"
[..]

The problem is that I have a +2h timezone offset, so that my script shows dates early by 2hours

date "+%z %Z"
+0200 IST

How can I adjust the script to use the timezone offset?

Thanks,

Maxim_united
  • 1,911
  • 1
  • 14
  • 23
  • possible duplicate of [Bash: get date and time from another time zone](http://stackoverflow.com/questions/26802201/bash-get-date-and-time-from-another-time-zone) – tripleee Mar 04 '15 at 12:50
  • I currently solved via `date -d"$(date -d"70-1-1 + $SECONDS sec - $UPTIME sec + $TIMESTAMP sec" +"%d/%m/%Y %T") $(date +%z) hours" +"%d/%m/%Y %T"` - thoughts? – Maxim_united Mar 04 '15 at 13:12

1 Answers1

1

You can use date with -u parameter which according to the manual it displays the output in UTC.

JuniorCompressor
  • 19,631
  • 4
  • 30
  • 57