Using only native ANT tasks, how can I create a custom ANT task to do the following:
- Calculate the the number of days since January 1, 2000 local time and store it in a property.
- Calculate the number of seconds since midnight local time, divided by 2 and store it in a property.
The above property values will then be appended to others and written to a file.
ANT is not a general purpose programming language, so you need to write a custom task or alternatively use something like the groovy plugin
The following example demonstrates how a groovy task using the Joda Time library can set the properties as you've specified.
I can't recommend Joda Time highly enough, standard Date and Time manipulation in Java just sucks!
Additional notes
The groovy task above will require the following jars on your classpath:
I'd recommend using the ivy plugin to manage these by adding a "resolve" target that downloads the jars and sets the classpath automatically:
The following is the ivy.xml that lists the dependencies to be downloaded: