View Javadoc

1   /***
2    *  The contents of this file are subject to the Mozilla Public
3    *  License Version 1.1 (the "License"); you may not use this file
4    *  except in compliance with the License. You may obtain a copy of
5    *  the License at http://www.mozilla.org/MPL/
6    * 
7    *  Software distributed under the License is distributed on an "AS
8    *  IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9    *  implied. See the License for the specific language governing
10   *  rights and limitations under the License.
11   * 
12   *  The Original Code is pow2toolkit library.
13   * 
14   *  The Initial Owner of the Original Code is 
15   *  Power Of Two S.R.L. (www.pow2.com)
16   *
17   *  Portions created by Power Of Two S.R.L. are 
18   *  Copyright (C) Power Of Two S.R.L.  
19   *  All Rights Reserved.
20   * 
21   * Contributor(s): 
22   */
23  
24  package com.pow2.util;
25  
26  
27  import java.text.SimpleDateFormat;
28  import java.text.ParsePosition;
29  
30  
31  /***
32   *  SQL Util class.
33   */
34  public class SQLUtil
35  {
36    /***
37     *  Get a Date object from the input date string representation.
38     *  <br>
39     *  The date representation has got the "dd/MM/yyyy" format.
40     *
41     *  @param  dateString the date string representation
42     *  @return the Date object builded from the input date string
43     */
44    public static java.sql.Date getDate(String dateString)
45    {
46  	return getDate(dateString, "dd/MM/yyyy");
47    }
48  
49  
50    /***
51     *  Get a Date object from the input date string representation.
52     *
53     *  @param  dateString the date string representation
54     *  @param  format     the SimpleDateFormat format.
55     *                     See <code>java.text.SimpleDateFormat</code> api for
56     *                     further informations.
57     *  @return the Date object builded from the input date string
58     */
59    public static java.sql.Date getDate(String dateString, String format)
60    {
61  	// Format the current time and parse the previous string back into a Date.
62  	SimpleDateFormat formatter = new SimpleDateFormat (format);
63  	ParsePosition  pos         = new ParsePosition(0);
64  	java.util.Date myDate      = formatter.parse(dateString, pos);
65  	return new java.sql.Date(myDate.getTime());
66    }
67  }