This small Sublime Text plugin adds three commands:
- Insert current date β
YYYY-MM-DD - Insert current time β
hh:mm(24-hour) - Insert date + time β
YYYY-MM-DD hh:mm
Works both for inserting and replacing a selection.
In Sublime Text:
Tools β Developer β New Pluginβ¦
Replace the contents with:
import sublime
import sublime_plugin
from datetime import datetime
def insert_text(edit, view, text):
for region in view.sel():
if region.empty():
view.insert(edit, region.begin(), text)
else:
view.replace(edit, region, text)
class InsertIsoDateCommand(sublime_plugin.TextCommand):
def run(self, edit):
insert_text(edit, self.view, datetime.now().strftime("%Y-%m-%d"))
class InsertIsoTimeCommand(sublime_plugin.TextCommand):
def run(self, edit):
insert_text(edit, self.view, datetime.now().strftime("%H:%M"))
class InsertIsoDatetimeCommand(sublime_plugin.TextCommand):
def run(self, edit):
insert_text(edit, self.view, datetime.now().strftime("%Y-%m-%d %H:%M"))Save as e.g.:
InsertTimestamps.py
Sublime reloads plugins automatically.
Press:
Ctrl+Shift+P(Windows / Linux)Cmd+Shift+P(macOS)
Then type:
Insert Iso DateInsert Iso TimeInsert Iso Datetime
Open:
Preferences β Key Bindings
Add something like:
[
{ "keys": ["ctrl+alt+d"], "command": "insert_iso_date" },
{ "keys": ["ctrl+alt+t"], "command": "insert_iso_time" },
{ "keys": ["ctrl+alt+shift+t"], "command": "insert_iso_datetime" }
]Change bindings to whatever suits your workflow.
You now have quick-insert ISO timestamps in Sublime Text.
If you want variations, the formats can easily be changed to include:
- seconds / milliseconds
- UTC timestamps
- full ISO-8601
YYYY-MM-DDTHH:mm - RFC-3339 style output
Just edit the strftime() strings in the plugin.
This is a very minimal plugin. If you want something more serious, consider either InsertDate or Timenow from Package Control.