Skip to content

Instantly share code, notes, and snippets.

@jordan-brough
Created November 3, 2012 13:50
Show Gist options
  • Save jordan-brough/4007432 to your computer and use it in GitHub Desktop.
Save jordan-brough/4007432 to your computer and use it in GitHub Desktop.
Splunk-friendly timestamp plugin snippet for Sublime Text 2
  1. Choose: Tools > New Plugin

  2. Paste in the contents of "timestamp.py" below

  3. Save as timestamp.py in ~/Library/Application Support/Sublime Text 2/Packages/User/ (should be the default directory that pops up when you save)

  4. Choose: Sublime Text 2 > Preferences > Key Bindings - User

  5. Add:

    { "keys": ["super+ctrl+t"], "command": "timestamp" }

To make command+ctrl+t perform the insertion.
Make sure to add a comma after the previous keymap entry, if present.

import sublime, sublime_plugin
from datetime import datetime
class TimestampCommand(sublime_plugin.TextCommand):
def run(self, edit):
stamp = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ ")
for r in self.view.sel():
if r.empty():
self.view.insert (edit, r.a, stamp)
else:
self.view.replace(edit, r, stamp)
@chrispx
Copy link

chrispx commented Apr 23, 2014

I would need UTC + 2 hours. How could this be achieved?

Thank you.

@7osema
Copy link

7osema commented Jun 20, 2016

Hi chrispx,

for me it worked using datetime.now() instead of datetime.utcnow()

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