Skip to content

Instantly share code, notes, and snippets.

@merriam merriam/

forked from reima/
Last active Dec 19, 2015
What would you like to do?
# -*- coding: utf-8 -*-
from datetime import datetime
import sublime_plugin
# Adding too much documentation:
# 1. The original Gist had %M instead of %m in the strftime() class. %M means minute,
# while %m means month as a decimal.
# 2. To install this:
# Sublime's menu Tools -> New Plugin...,
# Paste this gist over the sample given (use the raw button to see the gist as text)
# Save the file in your Sublime Packages directory. File -> Save As.. should suggest
# an appropriate spot. I recommend the name
# All done. It should work immediately.
# 3. To use this:
# Type "date" and hit tab. Also try the words `isoD`, `now`, `datetime`, `utcnow`, `utcdatetime`,
# `date` and `time` followed by tab. You may have to hit tab twice if you have another matching
# symbol in your current namespace.
class TimestampCommand(sublime_plugin.EventListener):
"""Expand `isoD`, `now`, `datetime`, `utcnow`, `utcdatetime`,
`date`, `time`, and `timestamp`
def on_query_completions(self, view, prefix, locations):
if prefix in ('isoD', 'now', 'datetime'): # 2013-06-27T23:34:00
val ='%Y-%m-%dT%H:%M:%S')
elif prefix in ('utcnow', 'utcdatetime'): # 2013-06-28T06:35:54
val = datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S')
elif prefix == 'date': # 2013-06-27
val ='%Y-%m-%d')
elif prefix == 'time': # 23:34:12
val ='%H:%M:%S')
elif prefix == 'timestamp': # Thu, 27 Jun 2013 23:36:15
val ='%a, %d %b %Y %H:%M:%S')
val = None
return [(prefix, prefix, val)] if val else []

This comment has been minimized.

Copy link
Owner Author

merriam commented Jul 6, 2013

This is now maintained in a repository, because the Gist does not allow pull requests. Having several versions floating of the gist floating around seems counterproductive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.