I'd like to store a UNIX timestamp (i.e. seconds since epoch) in an Ant property for later use in a couple build targets. It appears to be impossible:
<tstamp>
<format property="build.time" />
</tstamp>`
...generates a formatted timestamp.
<propertyfile file="foo.properties">
<entry key="build.time" type="date" default="now" />
</propertyfile>
...also generates a formatted timestamp.
I'd hope that this is possible without using <exec>
or similar (since we will sometimes run the build on Windows).
Unix timestamps usually are stored in 32-bit signed integers. A 32-bit signed integer uses the first bit to determine the sign, and the next 31 to encode the number, so it can represent integers from −(231) to 231 − 1.
A few things you should know about Unix timestamps:Unix timestamps are always based on UTC (otherwise known as GMT). It is illogical to think of a Unix timestamp as being in any particular time zone. Unix timestamps do not account for leap seconds.
**\*.sql means "in the given directory and inside all of its subdirectories, all the files that end with .sql"
Unix is an operating system originally developed in the 1960s. Unix time is a way of representing a timestamp by representing the time as the number of seconds since January 1st, 1970 at 00:00:00 UTC.
A quick google brings up:
http://www.norio.be/blog/2010/08/getting-unix-time-epoch-ant-build-file
<target name="print-epoch">
<script language="javascript">
<![CDATA[
property = project.setProperty("now",Math.floor((new Date()).getTime()/1000));
]]>
</script>
<echo message="${now}" />
</target>
Other approaches that would be cleaner IMO would be to
create your own custom anttask. It's really not that difficult; http://ant.apache.org/manual/develop.html
Use the Maven exec plugin to execute Java to do this: http://mojo.codehaus.org/exec-maven-plugin/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With