PyCharm: Inserting the date and time
pycharm
Solution
You can set up a custom Live Template for that. As "Edit Template Variables Dialog" page of PyCharm documentation clearly states, for any variable you use in your Live Template you can define an expression, that can make use of PyCharm's several built-in functions.
One of these functions is `date()`. Call it without arguments or specify a date format.
So, steps for setting up a Live Template in your case are:
- Open `Settings -> IDE Settings -> Live Templates`
- Choose `Python` from list and click `Add` (green plus to the left) or press `Alt+Insert`.
- Enter an abbreviation to use and template description.
- In `Template text` area write `$DATE$` (you can use another variable name though).
- Click `Edit variables`.
- Choose expression field next to `DATE` (or whatever you used) and put `date()` there. You may specify date format, if neccessary, e. g. `date("dd MMM yyyy")`.
- Click `OK`.
- Don't forget to define a context for the Live Template (blue link right under `Template text` area). Choose `Python` at least.
- Close `Settings` dialog with `OK`.
- You may now use a Live Template you defined to insert today's date: enter an abbreviation you chose and press Tab (by default).
EDIT: applicable in PyCharm 3.4 Professional Edition
EDIT2: to insert time use another PyCharm's built-in function -- `time()`
EDIT3: It appears to be implemented with Java's Velocity templating language. So the symbols in the date string are same as those. Something like:
Symbol Meaning Presentation Example
------ ------- ------------ -------
G era designator (Text) AD
y year (Number) 1996
M month in year (Text & Number) July & 07
d day in month (Number) 10
h hour in am/pm (1~12) (Number) 12
H hour in day (0~23) (Number) 0
m minute in hour (Number) 30
s second in minute (Number) 55
S millisecond (Number) 978
E day in week (Text) Tuesday
D day in year (Number) 189
F day of week in month (Number) 2 (2nd Wed in July)
w week in year (Number) 27
W week in month (Number) 2
a am/pm marker (Text) PM
k hour in day (1~24) (Number) 24
K hour in am/pm (0~11) (Number) 0
z time zone (Text) Pacific Standard Time
' escape for text (Delimiter)
'' single quote (Literal) '
Problem
Is there a way to insert the current date and time in PyCharm via a button or hot keys instead of having to retype it every time? Essentially I would love to type `Ctrl + d` (or something) and it would paste the current date and time.