Date Tool Example
This Example shows you how to display date and time velocity. The methods used in this example are described below:-
1:- Initialize velocity run
time
engine through method init().
2:- Create object of
VelocityContext Class.
3:- Create Template
class object, Template
class object is used for
controlling template methods and properties.
template.merge(context, writer): Merge method of the Template class
is used here for
merging the VelocityContext class objects to produce
the output. Template class object is used for
controlling template methods and properties.
Date date = cal.getTime(): Here we created Date class object by using Calender class object.
$date.getHours(), $date.getMinutes(), $date.getSeconds(): getHours() is used here to print hours, getMinutes() is used here to print minutes, getSeconds() is used here to print seconds.
$date.getDate(), $date.getMonth(), $date.getYear(): getDate() is used here to print date, getMonth() is used here to print month, getYear() is used here to print year.
DateToolClass.java
package velocity.dateTool; |
Product.vm
$date; |
Output:
Fri Aug 22 17:15:15 IST 2008; |