01: package com.technoetic.xplanner.format;
02:
03: import javax.servlet.http.HttpServletRequest;
04: import javax.servlet.jsp.PageContext;
05: import java.text.ParseException;
06: import java.text.SimpleDateFormat;
07: import java.util.Date;
08:
09: public class DateTimeFormat extends AbstractFormat {
10: private SimpleDateFormat formatter = null;
11:
12: public DateTimeFormat(HttpServletRequest request) {
13: String format = getFormat(request, "format.datetime");
14: if (format != null) {
15: formatter = new SimpleDateFormat(format);
16: } else {
17: formatter = new SimpleDateFormat();
18: }
19: }
20:
21: public String format(Date value) {
22: return value != null ? formatter.format(value) : "";
23: }
24:
25: public Date parse(String date) throws ParseException {
26: return formatter.parse(date);
27: }
28:
29: public static String format(PageContext pageContext, Date value) {
30: return new DateTimeFormat(((HttpServletRequest) pageContext
31: .getRequest())).format(value);
32: }
33:
34: public static String format(HttpServletRequest request, Date value) {
35: return new DateTimeFormat(request).format(value);
36: }
37: }
|