The date type in Java is quick to determine if the dates are valid.

Source: Internet
Author: User

If the date is illegal, throw an exception to try {String date_str = "5555-22-33"; SimpleDateFormat format=new SimpleDateFormat ("Yyyy-mm-dd"); Format.setlenient (false);D ate Date = Format.parse (date_ STR);} catch (Exception ex) {ex.printstacktrace (); SYSTEM.OUT.PRINTLN ("date not valid");}


Description of the notes in the JDK:

/**     * Specify whether or not date/time parsing are to be lenient.     with * Lenient parsing, the parser could use heuristics to interpret inputs that     * does not precisely match this objec T ' s format.  With strict parsing,     * Inputs must match this object ' s format.     *     * <p>this method is equivalent to the following call.     * <blockquote><pre>     *  Getcalendar (). Setlenient (lenient)     * </pre></blockquote >     *     * <p>this leniency value is overwritten by a call to {@link     * #setCalendar (Java.util.Calendar ) Setcalendar ()}.     *     * @param lenient when {@code true}, parsing is lenient     * @see java.util.calendar#setlenient (Boolean) */     Public    void Setlenient (Boolean lenient)    {        calendar.setlenient (lenient);    }


The date type in Java is quick to determine whether the dates are legitimate.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.