在Ant属性中存储UNIX时间戳?

| 我想在Ant属性中存储UNIX时间戳(即自纪元以来的秒数),以便以后在几个构建目标中使用。似乎不可能:
<tstamp>
  <format property=\"build.time\" />
</tstamp>`
...生成格式化的时间戳。
<propertyfile file=\"foo.properties\">
    <entry key=\"build.time\" type=\"date\" default=\"now\" />
</propertyfile>
...还会生成格式化的时间戳记。 我希望不用
<exec>
或类似的东西就可以做到这一点(因为有时我们会在Windows上运行该版本)。     
已邀请:
一个快速的谷歌提出: 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>
可以使IMO更清洁的其他方法是 创建自己的自定义anttask。确实没有那么困难; http://ant.apache.org/manual/develop.html 使用Maven exec插件执行Java可以做到这一点: http://mojo.codehaus.org/exec-maven-plugin/     

要回复问题请先登录注册