build.xml to set date and time as file name

三世轮回 提交于 2019-12-10 04:26:49

问题


I want to set file name with date and time attached to it so I want to create file named as behat-20140913-195915.html however the example below sets the name as behat-yyyymmdd-hhiiss.html. Anyone know the solution to problem?

I followed this example

Note: These two don't work too: ${DSTAMP} ${TSTAMP}

<?xml version="1.0" encoding="UTF-8"?>

<project name="Sport" default="build-default" basedir=".">

    <tstamp>
        <format property="TODAY_MY" pattern="yyyymmdd-hhiiss"  locale="en,UK" />
    </tstamp>

    <target name="build" description="Runs everything in order ..." depends="behat-bdd" />

    <target name="behat">
        <echo msg="Running Behat tests ..." />
        <exec logoutput="true" checkreturn="true"
              command="bin/behat -f progress --format html --out ${dir-report}/behat-${TODAY_MY}.html" dir="./" />
    </target>

</project>

回答1:


The tstamp task is documented in the ANT manual. It describes how the pattern format comes from the SimpleDateFormat object:

  • http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html

I suggest trying the following:

Example

Buildfile: build.xml

build:
     [echo] date: 20140913-203419

build.xml

<project name="demo" default="build">

  <tstamp>
      <format property="TODAY_MY" pattern="yyyyMMdd-HHmmss"  locale="en,UK" />
  </tstamp>

  <target name="build">
    <echo message="date: ${TODAY_MY}"/>
  </target>

</project>

Software versions

$ ant -v
Apache Ant(TM) version 1.9.4 compiled on April 29 2014

$ java -version
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)


来源:https://stackoverflow.com/questions/25825798/build-xml-to-set-date-and-time-as-file-name

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!