ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From T E Schmitz <>
Subject extract file date in a given format
Date Thu, 04 Jan 2007 22:31:54 GMT

I have a task which returns a file's date in epoch format (for use with 

<!-- usage : <filedate file="xxx.jar" property="date"/> -->
<scriptdef name="filedate" language="javascript">
     <attribute name="file"/>
     <attribute name="property"/>
         fileName = attributes.get("file");
         propName = attributes.get("property");
         file = new;
         last = file.lastModified();
         project.setNewProperty(propName, last);

I also need the date in a human readable format.

I tried to write a second script but am getting an 
IllegalArgumentException on "new Date(millis)":

<!-- usage : <formatdate millis="${millis}" format="yyMMddHHmm" 
property="formatted"/> -->
<scriptdef name="filedate" language="javascript">
     <attribute name="millis"/>
     <attribute name="format"/>
     <attribute name="property"/>
         millis = attributes.get("millis");
         format = attributes.get("format");
         propName = attributes.get("property");
         d = new java.util.Date(millis);
         f = new java.text.SimpleDateFormat(format);
	y = f.format(d);
         project.setNewProperty(propName, y);

Also: could I combine the two scripts and return 2 properties if format 
is specified?



Tarlika Elisabeth Schmitz

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message