Saving UNIX timestamp in Ant property?

I would like to save the UNIX timestamp (i.e. seconds from the era) in the Ant property for later use in a pair of build targets. This seems 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 hope this is possible without use <exec>or the like (since we will sometimes run builds on Windows).

+5
source share
1 answer

Google quick search:

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 would be

+4

All Articles