Date Formatter
Format dates in Sublime Text using PHP's date functions (Requires PHP)
Details
Installs
- Total 3K
- Win 2K
- Mac 792
- Linux 351
Oct 31 | Oct 30 | Oct 29 | Oct 28 | Oct 27 | Oct 26 | Oct 25 | Oct 24 | Oct 23 | Oct 22 | Oct 21 | Oct 20 | Oct 19 | Oct 18 | Oct 17 | Oct 16 | Oct 15 | Oct 14 | Oct 13 | Oct 12 | Oct 11 | Oct 10 | Oct 9 | Oct 8 | Oct 7 | Oct 6 | Oct 5 | Oct 4 | Oct 3 | Oct 2 | Oct 1 | Sep 30 | Sep 29 | Sep 28 | Sep 27 | Sep 26 | Sep 25 | Sep 24 | Sep 23 | Sep 22 | Sep 21 | Sep 20 | Sep 19 | Sep 18 | Sep 17 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Windows | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 2 |
Mac | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
Linux | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |
Readme
- Source
- raw.githubusercontent.com
Date Formatter
Select a date, choose a format, reformat.
Requirements
To use Date Formatter, you must have PHP installed.
Installation
First, make sure you have a PHP CLI interpretter installed.
Sublime Package Control
You can install Date Formatter using the excellent Package Control package manager for Sublime Text:
- Open “Package Control: Install Package” from the Command Palette (
Shift + Command + P
). - Select the “Date Formatter” option to install.
Git Installation
To install manually, clone to your “Packages” directory.
git clone https://github.com/pjdietz/sublime-date-formatter.git "Date Formatter"
Note: Date Formatter expects to be installed to a directory called “Date Formatter”.
Using
Date Formatter uses PHP's stringtotime()
and date()
functions to magically parse just about any string representation of a date or time and format it any way you'd like.
- Start by making a selection. You can select one date or several using multiple selections.
- Open the Command Palette with
Command + Shift + P
(OSX) and begin typing “format date”. Select it when you see it in the list. - Select the format you would like from the quick panel. Each item in the panel will contain a preview of the format using the first selected date.
- When you select the format, Date Formatter will replace each selected date with a reformatted version.
Configuration
Create a user settings file to configure Date Formatter. There are a couple things you can configured.
PHP Setup
The most important thing to configre is the path to PHP. If PHP in installed on your system with php
on the path, you can leave this as the default. Windows users will need to provide the path using forward slashes. Here's an example:
{
"php": "C:/php/php.exe"
}
To customize the available formats, look at the formats
setting. This setting must be a list. Each item of the list can either be:
- A string containing a date format
- A list containing a date format string and a label
The label will appear in the quick panel and can be anything you like. For help with the syntax for the date format strings, see the PHP manual's page on date()
.
Here are the default formats:
{
"formats": [
["Y-m-d", "SQL Date"],
["Y-m-d H:i:s", "SQL Date Time"],
["c", "ISO 8601"],
["r", "RFC 2822"],
"m/d/Y"
]
}
Custom Commands
You may want to add custom commands to the command palette for date formats you use frequently. To do this, create a new file in your Packages/User/
directory with the extenstion .sublime-commands
. The syntax for the file looks like this:
[
{
"caption": "Format SQL Date",
"command": "format_date",
"args": {"format": "Y-m-d H:i:s"}
}
]
More Fun
Insert Today's Date
If you use the Format Date command with an empty selection, it will insert a formatted string of the current time.
Relative Dates
PHP's strtotime()
is pretty magical. It can even handle relative dates like tomorrow
, yesterday
, next Thursday
, and 1 week 2 days 4 hours 2 seconds
. Play around with, and check out the PHP manual page on stringtotime()
.
Author
PJ Dietz
Copyright and license
Copyright 2013 PJ Dietz