日期:2014-05-17 浏览次数:20755 次
import java.io.StringWriter; import java.io.Writer; import java.util.Calendar; import java.util.TimeZone; import org.apache.velocity.Template; import org.apache.velocity.VelocityContext; import org.apache.velocity.app.Velocity; import org.apache.velocity.tools.generic.DateTool; public class DateToolExample { public static void main(String[] args) throws Exception { Velocity.init(); Template t = Velocity.getTemplate("./src/dateTool.vm"); VelocityContext ctx = new VelocityContext(); ctx.put("date", new DateTool()); Calendar aDate = Calendar.getInstance(TimeZone.getTimeZone("PST")); aDate.set(200, 11, 25); ctx.put("aDate", aDate); Writer writer = new StringWriter(); t.merge(ctx, writer); System.out.println(writer); } }