Here you can find the source of isDateValid(String date, Locale locale)
Parameter | Description |
---|---|
date | date passed as argument |
public static boolean isDateValid(String date, Locale locale)
//package com.java2s; //License from project: Apache License import java.text.DateFormat; import java.text.ParseException; import java.util.Locale; public class Main { /**/*from w ww. ja va2 s . com*/ * Because the date passed as argument can be in java format, and because not all formats are compatible * with joda-time, this method checks if the date string is valid with java. In this way we can use the * proper DateTime without changing the output. * * @param date date passed as argument * @return true if is a java date */ public static boolean isDateValid(String date, Locale locale) { try { DateFormat format = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT, locale); format.parse(date); return true; } catch (ParseException e) { return false; } } }