Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

How to Create a Date Time Stamp in Sublime Text 2 on a Mac

View Default (OSX).sublime-keymap
1 2 3 4 5
[
{"keys": ["super+alt+ctrl+d"], "command": "add_date_time_stamp" },
{"keys": ["super+alt+d"], "command": "add_date_stamp" },
{"keys": ["super+alt+t"], "command": "add_time_stamp" }
]
View Default (OSX).sublime-keymap
1 2 3 4 5 6 7 8 9 10 11 12 13 14
import datetime, getpass
import sublime, sublime_plugin
 
class AddDateTimeStampCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.view.run_command("insert_snippet", { "contents": "%s" % datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") } )
 
class AddDateStampCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.view.run_command("insert_snippet", { "contents": "%s" % datetime.datetime.now().strftime("%Y-%m-%d") } )
 
class AddTimeStampCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.view.run_command("insert_snippet", { "contents": "%s" % datetime.datetime.now().strftime("%H:%M:%S") } )
Owner

Instructions:

  1. Click on Menu: Tools > New Plugin
    1. Paste the python plugin code below (change it to your hearts desire)
    2. Save the file (name it what you want) I named mine "datetimestamp.py"
  2. Click on Preferences Menu (Click Sublime Text 2 Menu > Preferences) > Key Bindings - User
    1. Paste the Default (OSX).sublime-keymap code below into your file.
    2. Save your file
  3. Test it out, you don't have to restart Sublime Text 2 in order for the changes to take effect

If you make your own version or improve on this at all please fork the project and give back to the rest of us how you like to do things. I'm always up for learning how someone else does this!

What would be an ideal way to implement this into a custom snippet?

How do you implement it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.