Alex Rivera | Logout

Is there a shortcut for inserting date/time in IntelliJ IDEA?

Asked 2012-01-03T15:48:00.447
46

I'd like to add date/time for comments so that I can know when I did those changes, and I am doing that by hand now because I could not find a shortcut. What a great plus for IntelliJ IDEA to have a shortcut for that!

Edit
Report

1 Answer

73

You can create your own:

  1. In Settings, go to Live Templates
  2. Add a new template with the abbreviation "date"
  3. For "template text", specify $date$. Now the "Edit Variables" button should be enabled.
  4. Edit the variables, and set $date$ to use the expression date().
  5. 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.

answered 2012-01-03T15:52:52.947

Your Answer