ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

Insert​Date

by FichteFoll ALL

Insert the current date/time according to given formatting or timezone

Details

Installs

  • Total 32K
  • Win 17K
  • Mac 8K
  • Linux 7K
Dec 21 Dec 20 Dec 19 Dec 18 Dec 17 Dec 16 Dec 15 Dec 14 Dec 13 Dec 12 Dec 11 Dec 10 Dec 9 Dec 8 Dec 7 Dec 6 Dec 5 Dec 4 Dec 3 Dec 2 Dec 1 Nov 30 Nov 29 Nov 28 Nov 27 Nov 26 Nov 25 Nov 24 Nov 23 Nov 22 Nov 21 Nov 20 Nov 19 Nov 18 Nov 17 Nov 16 Nov 15 Nov 14 Nov 13 Nov 12 Nov 11 Nov 10 Nov 9 Nov 8 Nov 7 Nov 6
Windows 1 1 0 2 2 0 1 0 1 2 3 2 2 4 5 1 4 2 1 2 2 1 1 2 0 0 0 1 0 5 4 0 1 4 0 0 4 0 0 1 1 2 1 3 1 3
Mac 0 2 2 1 0 2 0 2 0 0 3 1 1 1 0 0 1 2 1 0 0 0 0 1 0 0 0 0 0 1 2 0 1 2 1 0 1 0 0 0 0 0 0 0 0 1
Linux 0 0 1 0 0 1 2 2 0 0 1 2 3 1 1 1 2 2 0 1 0 0 0 0 0 0 0 0 3 3 1 1 0 0 2 1 1 0 0 1 0 1 1 0 1 0

Readme

Source
raw.​githubusercontent.​com

InsertDate - Sublime Text Plugin

A plugin for Sublime Text 2 and 3 that inserts the current date and/or time according to the format specified, supporting named timezones.

insertdate

For a brief introduction about the accepted formatting syntax, see http://strfti.me/. Might yield different results, see below.

Installation

You must install this package with Package Control, under InsertDate.

Upon installation, you will be asked to select your local timezone. This is required for pretty formatting of the %Z variable and should be set, but InsertDate will work without it. You can change this setting at any time with the “InsertDate: Select Timezone” command from the command palette.

Usage

The quick panel (see gif) opens on F5 and shows a selection of pre-defined settings that can be modified. See Settings on how to do that.

However, there are many more default key bindings available to provide you with the most-needed formats and a command that allows you to insert your own format and output timezone on the fly.

Command Examples

The following is an excerpt of the default key bindings (on OSX: super instead of ctrl):

[
// Insert datetime using default format text
  { "keys": ["ctrl+f5", "ctrl+f5"],
    "command": "insert_date" },

// Insert datetime using the specified format
  // Locale date
  { "keys": ["ctrl+f5", "ctrl+d"],
    "command": "insert_date",
    "args": {"format": "%x"} },

  // Locale time
  { "keys": ["ctrl+f5", "ctrl+t"],
    "command": "insert_date",
    "args": {"format": "%X"} },

  // Full iso date and time
  { "keys": ["ctrl+f5", "ctrl+i"],
    "command": "insert_date",
    "args": {"format": "iso"} },

  // Locale date and time converted to UTC (with timezone name)
  { "keys": ["ctrl+f5", "ctrl+u"],
    "command": "insert_date",
    "args": {"format": "%c %Z", "tz_out": "UTC"} },

  // Unix time (seconds since the epoch, in UTC)
  { "keys": ["ctrl+f5", "ctrl+x"],
    "command": "insert_date",
    "args": {"format": "unix"} },

  // ... and many more

// Prompt for user input ("format" behaves as default text)
// and output timezone, if none provided,
// and then insert the datetime with these parameters
  { "keys": ["alt+f5"],
    "command": "insert_date_prompt" },

// Show the panel with pre-defined options from settings
  { "keys": ["f5"],
    "command": "insert_date_panel" }
]

Settings

Settings can be accessed using the menu (Preferences > Package Settings > InsertDate > Settings - User/Default) or the command palette (“Preferences: InsertDate Settings - User/Default”).

You can also view the default settings here.

Format Examples

For the accepted formatting syntax, see http://strfti.me/ for an introduction and datetime.strftime() behavior for all details. Note that the introduction uses a different library and thus may yield different results.

Here are some examples on how the values are interpreted:

Format string Parameters Resulting string
%d/%m/%Y %I:%M %p 12/08/2014 08:55
%d. %b %y 12. Aug 14
%H:%M:%S.%f%z 20:55:00.473603+0200
%Y-%m-%dT%H:%M:%S.%f%z 2014-08-12T20:55:00.473603+0200
iso {'tz_out': 'UTC'} 2014-08-12T18:55:00+00:00
%c UTC%z {'tz_in': 'local'} 12.08.2014 20:55:00 UTC+0200
%X %Z {'tz_in': 'Europe/Berlin'} 20:55:00 CEST
%d/%m/%Y %I:%M %Z {'tz_in': 'America/St_Johns'} 12/08/2014 08:55 NDT
%c %Z (UTC%z) {'tz_out': 'EST'} 12.08.2014 13:55:00 EST (UTC-0500)
%x %X %Z (UTC%z) {'tz_out': 'America/New_York'} 12.08.2014 14:55:00 EDT (UTC-0400)
unix 1407869700

Notes:

  • CET is my actual timezone.
  • %c, %x and %X are representative for Locale’s appropriate time representation.
  • %p also corresponds to the locale's setting, thus using %p e.g. on a German system gives an empty string.

Snippet Macros

You can use the insert_date command in combination with snippets using macros. Here is an example:

[
    { "command": "insert_snippet", "args": {"contents": "Date: $1\nTime: $2\nSomething else: $0"} },
    { "command": "insert_date", "args": {"format": "%x"} },
    { "command": "next_field" },
    { "command": "insert_date", "args": {"format": "%X"} },
    { "command": "next_field" }
]

Check the documentation for Macros and Commands for further information.

Command Reference

insert_date_panel

Open a quick panel with pre-defined format settings

insert_date

Insert the current date/time with specified formatting

Parameters

  • format (str) - Default: '%c' (configurable in settings)

A format string which is used to display the current time. See http://strfti.me/ for an introduction and datetime.strftime() behavior for all details.

  • tz_in (str) - Default: 'local' (configurable in settings and recommended to change)

Defines in which timezone the current time (read from your system) will be interpreted.

May be one of these values or 'local'.

  • tz_out (str) - Default: None

Defines on which timezone the output time should be based.

By default, uses the same timezone as tz_in. May be one of these values or 'local' (which does not support %Z, but %z).

insert_date_prompt

Open a small panel where you can specify the format string manually. The string passed in format will be used as default text if available. Accepts the same parameters as insert_date.