开发者

In Eclipse how to automatically print current date/time in the comments?

I have element-level comments in my code & I need to say when was the last time I modified a piece of code. Since it might be difficult to do this automatically when I save the document in question, I was 开发者_运维问答looking for some semi-automatic solution where I press a shortcut & poof the date/time appears at my cursor.

E.g.

/**
 * modified by @author Chantz last on <ENTER CURRENT DATE TIME HERE>
 */
public class EclipsePrintDateTimePlease {
...

UPDATE Eclipse versions I use are Helios & Galileo (I have different workstations).


Write a template for a keyword, for example date, that uses Eclipse date and time variables. After doing this, you will be able to expand the keyword into a date with Ctrl-Space.

For details, have a look at http://www.ibm.com/developerworks/opensource/library/os-eclipse-galcode/index.html

However, what you probably want instead is putting your code into some sort of versioning system (Subversion, git, Hg, ...) and use their capabilities to keep track on your versions and when you checked them in.

///BR, Jens Carlberg


The date variable in comment templates supports a format.

From the context help:

${id:date[(format[, locale])]} Evaluates to the current date in the specified format and locale. 'format' and 'locale' are optional parameters. 'format' is a pattern compatible with java.text.SimpleDateFormat. 'locale' is an RFC 3066 locale ID.

Examples:

${date}

${currentDate:date('yyyy-MM-dd')}

${d:date('EEEE dd MM yyyy', 'fr_CH')}

So setting a template to:

/**
 * modified by @author ${user} last on ${d:date('yyyy-MM-dd HH:mm:ss.SSS')}
 */

will result in a comment like:

/**
 * modified by @author Chantz last on 2017-08-04 09:54:23.130
 */


All the previous posts are correct:

  • In Eclipse/STS, Go to Windows-->Preferences and then
  • Go to Editor->Templates-> Click on New--> (put in a name and desciption) --> in the Pattenr Section add the ${date}${time}

In Eclipse how to automatically print current date/time in the comments?


Preferences --> Java --> Code Style --> Code Templates

In Eclipse how to automatically print current date/time in the comments?

Then press Shift + Alt + J will help you add date and time in existing file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜