Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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).

like image 782
Chantz Avatar asked Mar 15 '11 20:03

Chantz


People also ask

How do I turn on autocorrect in eclipse?

In the Window > Preferences menu, you can search for spell checking (located in General > Editors > Text Editors > Spelling) and there you can edit your spell checking options.

How do I print the current time in spring boot?

getTime(); DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); String formattedDate=dateFormat. format(date); System. out. println("Current time of the day using Calendar - 24 hour format: "+ formattedDate); } . . .

How do you call today's date in Java?

Code To Get Today's date in any specific FormatgetTime(); String todaysdate = dateFormat. format(date); System. out. println("Today's date : " + todaysdate);

How do I get commented code from Eclipse?

Finding comments is easy: search for "/*" or "//". And since comments have no formal relation to code, when is a comment "about" the code nearby, and when is it just a comment ("a sonnet to ...")?


2 Answers

You didn't specify which version of Eclipse you're using but, unless you are on a very old version, this should work:

  1. Go to Windows/Preferences.
  2. Select Java/Code Style/Code Templates from the preferences tree.
  3. In the code templates window, select the type of comments where you want timestamps to appear, e.g. getters, and click the Edit button. In the Edit Template dialog, positition the cursor wherever you like in the model comment, then click "Insert Variable...". There is no timestamp variable (i.e. a single variable that shows year, month, day, hour, minute, second, and microseconds) but you could do a date and then a time, e.g. ${date}${time}, to get something accurate to the second. That should be good enough for most people....
  4. I think you need to do the same steps for each of the different places where you want the timestamp to appear; I don't think there is any way to tell Eclipse to put a timestamp in every kind of comment in a single operation
like image 73
dLobatog Avatar answered Nov 16 '22 03:11

dLobatog


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

like image 38
JenEriC Avatar answered Nov 16 '22 03:11

JenEriC