Calender class object 사용하여 Date class object 를 생성한후 velocity 넘겨준다.
Date date = cal.getTime(): Here we created Date class object by using Calender class object.
$date.getHours() : getHours() is used here to print hours
$date.getMinutes() : getMinutes() is used here to print minutes
$date.getSeconds() : getSeconds() is used here to print seconds
$date.getDate() : getDate() is used here to print date
$date.getMonth() : getMonth() is used here to print month
$date.getYear() : getYear() is used here to print year
import java.io.*;
import java.util.*;
import org.apache.velocity.*;
import org.apache.velocity.app.*;
public class DateToolClass {
public static void main(String[] args) throws Exception {
Velocity.init();
Template template = Velocity.getTemplate("./src/dateTool.vm");
VelocityContext context = new VelocityContext();
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("PST"));
Date date = cal.getTime();
context.put("date", date);
Writer writer = new StringWriter();
template.merge(context, writer);
System.out.println(writer);
}
}
=======
input : dateTool.vm =====
$date;
Time
$date.getHours():$date.getMinutes():$date.getSeconds()
Date
$date.getDate()/$date.getMonth()/$date.getYear()
====== Output ======
Fri Aug 22
Time
Date 22/7/108te, getMonth() is used here to print month, getYear() is used here to print year.
'자바(JAVA)' 카테고리의 다른 글
| 메시지 규칙에 의해서 특정문자를 다른변수에 저장된 메시지로 치환하고 싶을때 (0) | 2009.02.21 |
|---|---|
| 원하는 위치의 문자열을 다른것으로 바꾸고 싶을때(치환) 간단 로직 (0) | 2009.02.21 |
| 소숫점 이하를 버리는 방식 2가지 (0) | 2009.02.19 |
| Java applet 과 javascript, html form 과의 통신방법 (0) | 2009.02.08 |
| velocity 에서 쓰이는 자료형 bool, number, String (0) | 2009.02.08 |
| velocity java class 객체들을 사용하고자 할 때 (0) | 2009.02.08 |
| velocity 에서 배열값을 화면에 그대로 표현하고 싶을 (0) | 2009.02.08 |
| Velocity 에서 xml 을 사용하여 표현하기 (0) | 2009.02.08 |
