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 31K
  • Win 16K
  • Mac 8K
  • Linux 6K
Apr 19 Apr 18 Apr 17 Apr 16 Apr 15 Apr 14 Apr 13 Apr 12 Apr 11 Apr 10 Apr 9 Apr 8 Apr 7 Apr 6 Apr 5 Apr 4 Apr 3 Apr 2 Apr 1 Mar 31 Mar 30 Mar 29 Mar 28 Mar 27 Mar 26 Mar 25 Mar 24 Mar 23 Mar 22 Mar 21 Mar 20 Mar 19 Mar 18 Mar 17 Mar 16 Mar 15 Mar 14 Mar 13 Mar 12 Mar 11 Mar 10 Mar 9 Mar 8 Mar 7 Mar 6 Mar 5
Windows 0 2 2 3 2 2 2 2 1 1 2 4 2 0 2 0 2 2 2 0 3 2 4 3 1 1 1 2 2 6 1 0 3 1 1 7 0 1 2 1 1 1 0 4 3 2
Mac 0 2 2 1 0 1 1 1 1 0 1 0 1 0 0 1 0 1 1 0 3 1 0 1 0 0 0 0 0 1 1 5 2 0 0 0 1 2 0 1 0 0 0 3 1 2
Linux 0 1 0 0 1 2 3 1 2 1 0 1 11 1 1 1 1 0 0 0 1 1 0 0 1 0 0 0 0 4 1 1 2 1 0 3 2 2 6 2 2 1 0 0 1 1

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.