Is there a shortcut for inserting date/time in IntelliJ IDEA?
Or you can just add the date whenever you create a new file by:
Settings > Editor | File and Code Templates > Includes (TAB) > File Header
Then type down something like:
/**
* Created by ${USER} on ${DAY} ${MONTH_NAME_SHORT}, ${YEAR}
*/
You can create your own:
- In Settings, go to Live Templates
- Add a new template with the abbreviation "date"
- For "template text", specify
$date$
. Now the "Edit Variables" button should be enabled. - Edit the variables, and set
$date$
to use the expressiondate()
. - Enable "Java comment" under the template's context and click OK.
Now when you type "date" and use the default completion gesture (Tab), it will replace "date" with the current date.
You can also make use of the time()
expression. Note that it doesn't seem like IntelliJ has great support for specifying the format of this date.
The date()
and time()
functions used by the live templates are based on standard java library functions. You can pass a standard java data/time formatter string as an argument to date()
and time()
. E.g. To get a timestamp like
2014-08-19T16:24:05.429Z
use in "Edit Template Variables" the variable expression:
date("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
to be assigned to the $date$ variable.
@Mark, Now IntelliJ has great support for specifying the date and time format ;-)