public static DateTime getJodaOrJavaDate ( final DateTimeFormatter dateFormatter , final String date ) throws Exception { if ( DateTimeUtils . isDateValid ( date , dateFormatter . getLocale ( ) ) ) { DateFormat dateFormat = DateFormat . getDateTimeInstance ( DateFormat . DEFAULT , DateFormat . DEFAULT , dateFormatter . getLocale ( ) ) ; Calendar dateCalendar = GregorianCalendar . getInstance ( ) ; dateCalendar . setTime ( dateFormat . parse ( date ) ) ; return new DateTime ( dateCalendar . getTime ( ) ) ; } return new DateTime ( date ) ; }
Returns a LocalDateTime depending on how the date passes as argument is formatted .