build.xml to set date and time as file name

BentCoder picture BentCoder · Sep 13, 2014 · Viewed 11.4k times · Source

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>

Answer

Mark O&#39;Connor picture Mark O'Connor · Sep 13, 2014

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

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)