使用Ant获取时间戳差异
我需要使用Ant计算时差。使用Ant获取时间戳差异,ant,timestamp,Ant,Timestamp,我需要使用Ant计算时差。 基本上它有两个变量。一个被指定为当前时间,另一个有不同的时间。我需要使用Ant获得时差。像下面这样。如果有人有密码,请回复 variable a = current time; variable b = different time echo (a - b) ; 时间戳1:${current.time.1}[${current.time.1.mill}] 时间戳2:${current.time.2}[${current.time.2.mill}] 差异:${res
基本上它有两个变量。一个被指定为当前时间,另一个有不同的时间。我需要使用Ant获得时差。像下面这样。如果有人有密码,请回复
variable a = current time;
variable b = different time
echo (a - b) ;
时间戳1:${current.time.1}[${current.time.1.mill}]
时间戳2:${current.time.2}[${current.time.2.mill}]
差异:${res}
时间戳1:${current.time.1}[${current.time.1.mill}]
时间戳2:${current.time.2}[${current.time.2.mill}]
差异:${res}
替代@LeFunes答案(并使用tstamp
任务)
project.setProperty(“task.diff”,
数学abs(
(Date.parse(project.getProperty(“task.stop”))+
+project.getProperty(“task.stop.millis”)-
(Date.parse(project.getProperty(“task.start”))+
+project.getProperty(“task.start.millis”))
任务在${task.diff}ms中完成
注:
这不考虑毫秒。
更新为考虑毫秒替代@ LeFunes回答(并使用<代码> tPAM任务)
project.setProperty(“task.diff”,
数学abs(
(Date.parse(project.getProperty(“task.stop”))+
+project.getProperty(“task.stop.millis”)-
(Date.parse(project.getProperty(“task.start”))+
+project.getProperty(“task.start.millis”))
任务在${task.diff}ms中完成
注:
这不考虑毫秒。
更新为考虑毫秒< p>这里有一个更简单的解决方案:
<script language="javascript">
project.setProperty('startTime', new Date().getTime());
</script>
...
<script language="javascript">
project.setProperty('elapsedTime', new Date().getTime() - startTime)
</script>
<echo>Elapsed time: ${elapsedTime} ms</echo>
project.setProperty('startTime',new Date().getTime());
...
project.setProperty('elapsedTime',new Date().getTime()-startTime)
运行时间:${elapsedTime}ms
这里有一个更简单的解决方案:
<script language="javascript">
project.setProperty('startTime', new Date().getTime());
</script>
...
<script language="javascript">
project.setProperty('elapsedTime', new Date().getTime() - startTime)
</script>
<echo>Elapsed time: ${elapsedTime} ms</echo>
project.setProperty('startTime',new Date().getTime());
...
project.setProperty('elapsedTime',new Date().getTime()-startTime)
运行时间:${elapsedTime}ms
如果不想使用JavaScript,可以使用实用程序提供的
Ant Contrib已经相当老了,我不知道是否还有人在维护它们,但是它们在Ant构建文件中非常流行,因为它们添加了一些非常有用的任务
我建议将ant-contrib-1.0b3.jar
包含在项目本身中。当其他人使用您的项目时,他们也会使用Ant Contrib jar。我将antlib/ac/ant-contrib-1.0b3.jar
放在项目的主目录下。我对所有可选jar使用ant lib
:
<project name="my.project"
...
xmlns:ac="antlib:net.sf.antcontrib">
...
<taskdef uri="antlib:net.sf.antcontrib"
resource="net/sf/antcontrib/antlib.xml">
<classpath>
<fileset dir="${basedir}/antlib/ac"/>
</classpath>
</taskdef>
....
...
....
现在,您可以这样使用您的数学任务:
<ac:math result="time.diff"
operation="-"
operand1="${diff.time}"
operand2="${initial.time}"/>
ac:
是在
实体中声明的XML命名空间,它通过
实体中的uri
参数连接到任务。这允许您拥有多个可选的Ant任务,这些任务可能具有重复名称的任务。如果您使用具有相同任务名称的多个可选任务库,这是一个好主意。如果您不想使用JavaScript,可以使用实用程序提供的
Ant Contrib已经相当老了,我不知道是否还有人在维护它们,但是它们在Ant构建文件中非常流行,因为它们添加了一些非常有用的任务
我建议将ant-contrib-1.0b3.jar
包含在项目本身中。当其他人使用您的项目时,他们也会使用Ant Contrib jar。我将antlib/ac/ant-contrib-1.0b3.jar
放在项目的主目录下。我对所有可选jar使用ant lib
:
<project name="my.project"
...
xmlns:ac="antlib:net.sf.antcontrib">
...
<taskdef uri="antlib:net.sf.antcontrib"
resource="net/sf/antcontrib/antlib.xml">
<classpath>
<fileset dir="${basedir}/antlib/ac"/>
</classpath>
</taskdef>
....
...
....
现在,您可以这样使用您的数学任务:
<ac:math result="time.diff"
operation="-"
operand1="${diff.time}"
operand2="${initial.time}"/>
ac:
是在
实体中声明的XML命名空间,它通过
实体中的uri
参数连接到任务。这允许您拥有多个可选的Ant任务,这些任务可能具有重复名称的任务。如果您使用多个具有相同任务名称的可选任务库,这是一个好主意。可能重复的任务库可能重复的任务库