01: /* $Id: DateTimeFormat.java 722 2006-10-30 10:15:22Z hengels $ */
02: package org.conform.format;
03:
04: import java.text.*;
05: import java.util.*;
06:
07: /**
08: * java.sql.Date
09: * @version $Revision: 722 $
10: */
11: public class DateTimeFormat extends AbstractFormat {
12: public DateTimeFormat() {
13: message = "validation.unparsableDateTime";
14: }
15:
16: public DateTimeFormat(String pattern) {
17: message = "validation.unparsableDateTime";
18: this .pattern = pattern;
19: }
20:
21: public java.text.DateFormat getFormat() {
22: if (pattern != null)
23: return new SimpleDateFormat(pattern, FormatFactory
24: .getInstance().getLocale());
25: else
26: return java.text.DateFormat.getDateTimeInstance(
27: java.text.DateFormat.SHORT,
28: java.text.DateFormat.SHORT, FormatFactory
29: .getInstance().getLocale());
30: }
31:
32: public String getHelp() {
33: return ((SimpleDateFormat) getFormat()).toPattern();
34: }
35:
36: public String format(Object value) {
37: return getFormat().format(value);
38: }
39:
40: public Object parse(String string) throws ParseException {
41: Date date = (Date) getFormat().parseObject(string);
42: return new java.sql.Timestamp(date.getTime());
43: }
44: }
|