欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Ant时间戳的使用

程序员文章站 2022-05-23 21:04:02
...

 

<?xml version="1.0" encoding="utf8"?>
<project name="DataInfo" basedir="." default="formatDate2">
		<description>print data info</description>
		
		<!--自带的时间Task -->
		<target name="default">
				<echo message="------ defalut target run ---------" />
				<!-- 必须有tstamp -->
				<tstamp/> 
				<echo message="DSTAMP = ${DSTAMP}" />
				<echo message="TSTAMP = ${TSTAMP}" />
				<echo message="TODAY = ${TODAY}" />
				<echo message="CURRENTDATE = ${DSTAMP}${TSTAMP}" />
		</target>
		
		<!--定义日期格式和前缀-->
		<tstamp prefix="ft">
				<!--定义日期格式 -->
				<format property="zh_date" locale="zh,CN" pattern="yyyy-MM-dd HH:ss:mm"/>
				<format property="en_date" locale="en,US" pattern="MM/dd/yyyy hh:mm aa"/>
		</tstamp>
		
		<!-- 日期前缀以及日期格式化 -->
		<target name="formatDate" depends="default">
				<echo message="------ formatDate target run ---------" />
				<echo message="Today is ${ft.zh_date} in China"/>
				<echo message="Today is ${ft.en_date} in US"/>
		</target>
		
		
		<!-- 定义格式-->
		<tstamp prefix="dd">
				<!-- pattern就是java里java.util.Date的日期格式 -->
				<format property="day" pattern="yyyy-MM-dd"/>
        <format property="time" pattern="HH:mm:ss"/>
        <format property="dt" pattern="yyyy-MM-dd HH:mm:ss.SSS"/>
		</tstamp>
		
		<target name="formatDate2" depends="default,formatDate">
				<echo message="------ formatDate2 target run ---------" />
				<echo message="Today is ${dd.day}" />
				<echo message="Current Time is ${dd.time}" />
				<echo message="Full Time is ${dd.dt}" />
		</target>
</project>