@Test public void getJodaOrJavaDate() throws Exception { DateTimeFormatter dateTimeFormatter = DateTimeUtils.getDateFormatter("HH:MM", "fr", "FR"); DateTime dateTime = DateTimeUtils .getJodaOrJavaDate(dateTimeFormatter, "4 juillet 2001 12:08:56 EEST"); assertEquals("12:07", dateTime.toString(dateTimeFormatter)); }
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); }
DateTimeUtils { 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); } }
DateTimeUtils { 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); }  }
DateTimeUtils { 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); }  static boolean isUnix(String locale); static boolean isMilliseconds(String locale); static boolean isDateValid(String date, Locale locale); static Locale getLocaleByCountry(String lang, String country); static DateTime getJodaOrJavaDate(final DateTimeFormatter dateFormatter, final String date); static DateTimeFormatter getDateFormatter(String format, String lang, String country); static DateTimeFormatter formatWithDefault(String lang, String country); }
DateTimeUtils { 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); }  static boolean isUnix(String locale); static boolean isMilliseconds(String locale); static boolean isDateValid(String date, Locale locale); static Locale getLocaleByCountry(String lang, String country); static DateTime getJodaOrJavaDate(final DateTimeFormatter dateFormatter, final String date); static DateTimeFormatter getDateFormatter(String format, String lang, String country); static DateTimeFormatter formatWithDefault(String lang, String country);  }