ant-user mailing list archives

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

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

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

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"/>
     <![CDATA[
         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);
     ]]>
</scriptdef>

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

-- 


Regards,

Tarlika Elisabeth Schmitz

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message