Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.kuali.student.r2.common.util.date;
  
  
  import java.util.Date;

Helper class that wraps jada's DateTimeFormatter. Has helper methods to mimic standard java methods and make refactoring cleaner User: gtaylor Date: 11/6/12 Time: 2:47 PM
 
 public class KSDateTimeFormatter  {
 
     protected DateTimeFormatter formatter;
     protected String pattern;

    
Creates a new formatter

Parameters:
pattern regex pattern for the format
 
     public KSDateTimeFormatter(String pattern) {
         try{
             this. = pattern;
 
             this. = DateTimeFormat.forPattern(pattern);
         }
         catch (IllegalArgumentException ex){
 
             throw new IllegalArgumentException("Illegal pattern cannot be parsed. pattern["pattern +"].");
         }
 
     }

    
Helper method that allows for a straight string to java.util.Date conversion. returns null if it cannot parse the string

Parameters:
stringDate
Returns:
A java.util.Date, or null if the input could not be parsed
Throws:
java.lang.UnsupportedOperationException if parsing is not supported
java.lang.IllegalArgumentException if the text to parse is invalid
 
     public Date parse(String stringDate){
         Date dRet = null;
 
         try{
             DateTime dt = .parseDateTime(stringDate);
             dRet = dt.toDate();
         }catch (IllegalArgumentException ex){
             dRet = null;
             throw new IllegalArgumentException(stringDate + " cannot be parsed with pattern["this. +"].");
         }
 
         return dRet;
     }

    
Helper method that allows a stright java.util.Date to String converstion

Parameters:
javaDate
Returns:
Throws:
java.lang.IllegalArgumentException if the javaDate is invalid
 
     public String format(Date javaDate){
         return this..print(new DateTime(javaDate));
     }

    
Helper method that allows a stright java.util.Date to String converstion

Parameters:
strDate
Returns:
Throws:
java.lang.IllegalArgumentException if the javaDate is invalid
 
     public String format(String strDate){
         return this..print(new DateTime(strDate));
     }

    
Get underlying Jada formatter

Returns:
 
     public DateTimeFormatter getFormatter(){
         return ;
     }

    
This returns the pattern used to create the formatter

Returns:
 
     public String getPattern() {
         return ;
     }
New to GrepCode? Check out our FAQ X