Skip to content

Instantly share code, notes, and snippets.

@sujit
Last active July 16, 2019 11:56
Show Gist options
  • Save sujit/9045e5f3256eddbbf413202a3b84a0c9 to your computer and use it in GitHub Desktop.
Save sujit/9045e5f3256eddbbf413202a3b84a0c9 to your computer and use it in GitHub Desktop.
Modify/Substract/Add hours offsets to UTC timestamps (eliot_debug.log)

Open JSON log & type the following to convert all timestamps:

7 hrs past (epoch format):

%s/"timestamp":\s*\zs\(\d\+\)\ze\./\=(str2nr(submatch(1)) - (7 * 60 * 60))/g

8 hrs forward (epoch format):

%s/"timestamp":\s*\zs\(\d\+\)\ze\./\=(str2nr(submatch(1)) + (8 * 60 * 60))/g

7 hrs past (human readable):

  • %s/"timestamp":\s*\zs\(\d\{10}\.\d*\ze,\)/\=strftime('"%c"', str2nr(submatch(1)) - (7 * 60 * 60))/g

Alternative

  • %s/"timestamp":\s*\zs\(\d\+\)\ze\./\=strftime("%Hhrs%Mmnts", submatch(1))/g

    Usage: Use str2nr(submatch(1)) - (7 * 60 * 60) as the second argument to strftime()

Python example

from datetime import datetime
import pytz

datetime.fromtimestamp(1350663248, tz= pytz.timezone('America/New_York'))
datetime.datetime(2012, 10, 19, 12, 14, 8, tzinfo=<DstTzInfo 'America/New_York' EDT-1 day, 20:00:00 DST>)

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment