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)
@stevecooperorg
Copy link

I can confirm this works on Sublime Text 3, Build 3033, Windows 64-bit, with these small changes;

  • In step 3, save timetstamp.py to C:\Users\your.name\AppData\Roaming\Sublime Text 3\Packages\User
  • In step 5, replace "super+ctrl+t" with "alt+ctrl+t"

Then invoke with alt+ctrl+t.

Thanks for this, Jordan!

@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