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

Insert​Date

by FichteFoll ALL Trending

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

Details

Installs

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