01: package com.xoetrope.sql;
02:
03: import java.text.SimpleDateFormat;
04: import java.util.Date;
05:
06: /**
07: * Date utilities for use with SQL queries
08: *
09: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
10: * the GNU Public License (GPL), please see license.txt for more details. If
11: * you make commercial use of this software you must purchase a commercial
12: * license from Xoetrope.</p>
13: * <p> $Revision: 1.4 $</p>
14: */
15: public class DateUtilities {
16: /**
17: * Return a string representing the date in the "dd-MM-yyyy" format
18: * @param d the raw date value
19: * @return the formatted date string
20: */
21: public static String formatDate(Date d) {
22: SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
23: return formatter.format(d);
24: }
25:
26: /**
27: * Converts a string representation of the date in long format to the "dd-MM-yyyy"
28: * string representation
29: * @param d the raw date string
30: * @return the formatted date string
31: */
32: public static String formatDate(String d) {
33: if ((d == null) || (d.length() == 0))
34: return d;
35:
36: Date newdate = new Date(Long.parseLong(d));
37: SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
38: return formatter.format(newdate);
39: }
40: }
|