KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xmlrpc > util > DateTool


1 /*
2  * Copyright 1999,2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17
18 package org.apache.xmlrpc.util;
19
20 import java.text.DateFormat JavaDoc;
21 import java.text.ParseException JavaDoc;
22 import java.text.SimpleDateFormat JavaDoc;
23 import java.util.Date JavaDoc;
24
25 /**
26  * Wraps a <code>DateFormat</code> instance to provide thread safety.
27  *
28  * @author <a HREF="mailto:hannes@apache.org">Hannes Wallnoefer</a>
29  * @author Daniel L. Rall
30  */

31 public class DateTool
32 {
33     protected static final String JavaDoc FORMAT = "yyyyMMdd'T'HH:mm:ss";
34
35     private DateFormat JavaDoc df;
36
37     /**
38      * Uses the <code>DateFormat</code> string
39      * <code>yyyyMMdd'T'HH:mm:ss</code>.
40      *
41      * @see #FORMAT
42      */

43     public DateTool()
44     {
45         df = new SimpleDateFormat JavaDoc(FORMAT);
46     }
47
48     /**
49      * @param d The date to format.
50      * @return The formatted date.
51      */

52     public synchronized String JavaDoc format(Date JavaDoc d)
53     {
54         return df.format(d);
55     }
56
57     /**
58      * @param s The text to parse a date from.
59      * @return The parsed date.
60      * @exception ParseException If the date could not be parsed.
61      */

62     public synchronized Date JavaDoc parse(String JavaDoc s)
63         throws ParseException JavaDoc
64     {
65         return df.parse(s);
66     }
67 }
68
Popular Tags