Skip to content

Instantly share code, notes, and snippets.

@robcowie
Created October 28, 2011 19:13
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 9 You must be signed in to fork a gist
  • Save robcowie/1323194 to your computer and use it in GitHub Desktop.
Save robcowie/1323194 to your computer and use it in GitHub Desktop.
Insert date and time stamps in Sublime Text 2
# -*- coding: utf-8 -*-
from datetime import datetime
import sublime_plugin
class TimestampCommand(sublime_plugin.EventListener):
"""Expand `isoD`, `now`, `datetime`, `utcnow`, `utcdatetime`,
`date` and `time`
"""
def on_query_completions(self, view, prefix, locations):
if prefix in ('isoD', 'now', 'datetime'):
val = datetime.now().strftime('%Y-%M-%dT%H:%M:%S')
elif prefix in ('utcnow', 'utcdatetime'):
val = datetime.utcnow().strftime('%Y-%M-%dT%H:%M:%S')
elif prefix == 'date':
val = datetime.now().strftime('%Y-%M-%d')
elif prefix == 'time':
val = datetime.now().strftime('%H:%M:%S')
else:
val = None
return [(prefix, prefix, val)] if val else []
@AndreaCensi
Copy link

The first "m" should be lowercase in %Y-%M-%dT%H:%M:%S.

@rizqidjamaluddin
Copy link

How to use: Sublime Text > Tools > New Plugin, paste this in, save somewhere in the ST2 packages directory and it'll be available immediately.

Great utility.

@merriam
Copy link

merriam commented Jun 28, 2013

Gists have no pull requests. I when I updated the gist, I stuck it a repo merriam/timestamp https://github.com/merriam/timestamp

@beipawel
Copy link

I'm new to ST2. I made a new package through new Plugin and restartet ST. If I type idoD+Tab nothing happens. Do I have to do something fancy?

@louisdoe
Copy link

louisdoe commented Nov 3, 2015

This is really, could you please translate it to make it work for Sublime Text 3 ?

@joerx
Copy link

joerx commented May 29, 2016

Works out of the box with Sublime Text 3.

@freedomlang
Copy link

Nice。^‿^。

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