01: package org.uispec4j.utils;
02:
03: import java.text.DateFormat;
04: import java.text.ParseException;
05: import java.text.SimpleDateFormat;
06: import java.util.Date;
07:
08: /**
09: * Utility for checking date as String formatted by a date format.
10: * By default, the date format u
11: * @see java.text.DateFormat
12: */
13: public class DateUtils {
14:
15: public static final SimpleDateFormat DEFAULT_DATE_FORMAT = new SimpleDateFormat(
16: "yyyy.MM.dd HH:mm");
17: private static DateFormat dateFormat = DEFAULT_DATE_FORMAT;
18:
19: private DateUtils() {
20: // Instanceless class
21: }
22:
23: /**
24: * Returns the date from the given value parsed by the date format.
25: */
26: public static Date getDate(String yyyyMMdd) throws ParseException {
27: synchronized (dateFormat) {
28: return dateFormat.parse(yyyyMMdd);
29: }
30: }
31:
32: /**
33: * Returns the Date as String formated by the date format.
34: */
35: public static String getStandardDate(Date date) {
36: synchronized (dateFormat) {
37: return dateFormat.format(date);
38: }
39: }
40:
41: /**
42: * Sets the date format.
43: */
44: public static void setDateFormat(DateFormat dateFormat) {
45: DateUtils.dateFormat = dateFormat;
46: }
47: }
|