Java Code Examples for org.joda.time.format.ISODateTimeFormat#basicDate()

The following examples show how to use org.joda.time.format.ISODateTimeFormat#basicDate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AmforeasUtils.java    From amforeas with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Check if a string has the ISO date format. Uses the ISODateTimeFormat.date() from JodaTime
 * and returns a DateTime instance. The correct format is yyyy-MM-dd or yyyyMMdd
 * @param arg the string to check
 * @return a DateTime instance if the string is in the correct ISO format.
 */
public static DateTime isDate (final String arg) {
    if (arg == null)
        return null;
    DateTime ret = null;
    DateTimeFormatter df;
    if (arg.contains("-")) {
        df = ISODateTimeFormat.date();
    } else {
        df = ISODateTimeFormat.basicDate();
    }

    try {
        ret = df.parseDateTime(arg);
    } catch (IllegalArgumentException e) {
        l.debug("{} is not a valid ISO date", arg);
    }

    return ret;
}