View Javadoc
1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *  
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *  
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License. 
18   *  
19   */
20  package org.apache.directory.api.util;
21  
22  
23  import java.util.Calendar;
24  import java.util.Date;
25  
26  
27  /**
28   * Gets the generalized time using the "Z" form of the g-time-zone.
29   * 
30   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
31   */
32  public final class DateUtils
33  {
34  
35      /**
36       * Private constructor.
37       */
38      private DateUtils()
39      {
40      }
41  
42  
43      public static Date getDate( String zuluTime )
44      {
45          try
46          {
47              return GeneralizedTime.getDate( zuluTime );
48          }
49          catch( Exception e )
50          {
51              throw new RuntimeException( e );
52          }
53      }
54  
55  
56      /**
57       * Gets the generalized time right now. {@link GeneralizedTime}
58       * 
59       * @return the generalizedTime right now
60       */
61      public static String getGeneralizedTime()
62      {
63          return new GeneralizedTime( Calendar.getInstance() ).toGeneralizedTime();
64      }
65  
66  
67      /**
68       * 
69       * @see #getGeneralizedTime()
70       *
71       * @param date the date to be converted to generalized time string
72       * @return given date in the generalized time string format
73       */
74      public static String getGeneralizedTime( Date date )
75      {
76          Calendar calendar = Calendar.getInstance();
77          calendar.setTime( date );
78          return new GeneralizedTime( calendar ).toGeneralizedTime();
79      }
80  
81  
82      /**
83       * 
84       * @see #getGeneralizedTime()
85       *
86       * @param time the time value to be converted to generalized time string
87       * @return given time in generalized time string format
88       */
89      public static String getGeneralizedTime( long time )
90      {
91          return getGeneralizedTime( new Date( time ) );
92      }
93  
94  }