Changeset 1392

Show
Ignore:
Timestamp:
04/04/09 13:16:54 (3 years ago)
Author:
amandel
Message:

Added methods for date parsing.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/java/org/jcoderz/commons/util/XsdUtil.java

    r1011 r1392  
    3434 
    3535import java.math.BigInteger; 
     36import java.util.Calendar; 
     37 
     38import javax.xml.bind.DatatypeConverter; 
     39 
     40import org.jcoderz.commons.types.Date; 
    3641 
    3742/** 
     
    220225   } 
    221226 
     227   /** 
     228    * Parses the given String as schema date time representation and returns 
     229    * a Date object holding the given time. 
     230    * This method must only be used after a JAXBContext has been initialized, 
     231    * otherwise it is likely that a NullpointerException is thrown. 
     232    * @param date the date time in schema dateTime 
     233    * @return a newly generated Date object representing the time given in the 
     234    *         date. 
     235    */ 
     236   public static Date fromDateTimeString (String date) 
     237   { 
     238      final Calendar cal = DatatypeConverter.parseDateTime(date); 
     239      cal.setLenient(false); 
     240      return new Date(cal.getTimeInMillis()); 
     241   } 
     242 
     243   /** 
     244    * Parses the given String as schema date representation and returns 
     245    * a Date object holding the given time. 
     246    * This method must only be used after a JAXBContext has been initialized, 
     247    * otherwise it is likely that a NullpointerException is thrown. 
     248    * @param date the date in schema date representation 
     249    * @return a newly generated Date object representing the time given in the 
     250    *         date. 
     251    */ 
     252   public static Date fromDateString (String date) 
     253   { 
     254      final Calendar cal = DatatypeConverter.parseDate(date); 
     255      cal.setLenient(false); 
     256      return new Date(cal.getTimeInMillis()); 
     257   } 
     258    
    222259}