KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > quikj > application > communicator > admin > controller > DateUtility


1 /*
2  * DateUtility.java
3  *
4  * Created on June 4, 2003, 11:13 AM
5  */

6
7 package com.quikj.application.communicator.admin.controller;
8
9 import java.util.*;
10
11 /**
12  *
13  * @author bhm
14  */

15 public class DateUtility
16 {
17     public static Date processInputDate(String JavaDoc date) // takes string of mm/dd/yyyy
18
{
19         return processInputDate(date, 0, 0, 0);
20     }
21     
22     public static Date processInputDate(String JavaDoc date, int hr, int min, int sec) // date = string of mm/dd/yyyy
23
{
24         if ((date == null) || (date.length() != 10))
25         {
26             return null;
27         }
28         
29         try
30         {
31             Calendar cal = Calendar.getInstance();
32             cal.setLenient(false);
33             cal.set(Calendar.YEAR, Integer.parseInt(date.substring(6)));
34             cal.set(Calendar.MONTH, Integer.parseInt(date.substring(0,2)) - 1);
35             cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(date.substring(3,5)));
36             cal.set(Calendar.HOUR_OF_DAY, hr);
37             cal.set(Calendar.MINUTE, min);
38             cal.set(Calendar.SECOND, sec);
39             
40             return cal.getTime();
41         }
42         catch(NumberFormatException JavaDoc ex)
43         {
44         }
45         catch (IllegalArgumentException JavaDoc ex1)
46         {
47         }
48         return null;
49     }
50     
51 }
52
Popular Tags