Reputation: 393
Is there a way in Java to have a string contain the date the program was compiled? When I start my program, I want the date it was last updated to appear without having to manually update it before I compile every time. Is there possibly a setting in eclipse I can use to insert the date in the code every time I compile it?
public class test {
public static void main(String[] args) {
String date = "2014-12-29"; //The string I want to automatically update.
System.out.println("Last updated: "+date);
}
}
Upvotes: 2
Views: 337
Reputation: 328564
Add a file to your project which contains the date. Read it from the file when you start. Use a tool like Gradle, Maven or Ant to build your project. All of them have one way or the other to update the file with the date.
Upvotes: 2