Java Year Format isYYYY(String strDate)

Here you can find the source of isYYYY(String strDate)

Description

is YYYY

License

Apache License

Declaration

public static boolean isYYYY(String strDate) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public final static String YYYY = "yyyy";

    public static boolean isYYYY(String strDate) {
        try {/* w  w  w  . ja  va  2  s .  c o m*/
            parse(strDate, YYYY);
            return true;
        } catch (ParseException pe) {
            return false;
        }
    }

    public static Date parse(String strDate, String pattern) throws ParseException {
        try {
            return getFormatter(pattern).parse(strDate);
        } catch (ParseException pe) {
            throw new ParseException("Method parse in Class DateUtil err: parse strDate fail.",
                    pe.getErrorOffset());
        }
    }

    private static SimpleDateFormat getFormatter(String parttern) {
        return new SimpleDateFormat(parttern);
    }
}

Related

  1. isPartialYear(String s, String yearFormat)
  2. isValidDateMMddyyyy(String theString)
  3. isYear(int y)
  4. isYear(String str, boolean nullCheck)
  5. isYearOnly(String input)
  6. lastDayOfWeek(String year, int week, String format)
  7. stringYYYYmmDDhhMMssToDate(String value)
  8. toDateString(String ddMMMyyyy)
  9. toYYYYMM(Date date)