checking the method call result in date variable if of two year format then prefix 20

I have one method which convert the string to date and return the date object as shown the in below formats that it check for is

String[] formatStrings = { "dd/MM/yyyy", "dd-MMM-yyyy" ,"dd/MM/YY" , "dd-MM-YY"};

now below is the call that is made

Date dealDate = convertStringToDate(dealDateString);

and the method call is as shown below its implementation

public  Date convertStringToDate(String stringValue) {
        Date iceDate = null;
        java.util.Date javaDate = new java.util.Date();
        String[] formatStrings = { "dd/MM/yyyy", "dd-MMM-yyyy" ,"dd/MM/YY" , "dd-MM-YY"};
        // DateFormat format = new SimpleDateFormat("dd/MM/yyyy",
        // Locale.ENGLISH);
        for (String formatString : formatStrings) {

            try {
                javaDate = new SimpleDateFormat(formatString)
                        .parse(stringValue);
                iceDate = new Date(javaDate);
                return iceDate;
            } catch (ParseException e) {
                logger.warn("##$$$$$### Error in invoice inside convertStringToDate method : ##$$$$$$#### "
                        + ErrorUtility.getStackTraceForException(e));

            }
        }
        return null;

    }

now my query is that whenever this call is made and it return the date object as shown below

Date dealDate = convertStringToDate(dealDateString);

now in this case i want to implement a check that dealdate variable should consist of a check lets say if date stored in date variable is 02/11/14

then in the above case year is in two digit format( YY) then it should be prefix with 20 so year would be finally like 2014 so a check should be made if in deal date variable year is in two digit format then it should be prefix with 20 always please implement how to put this check

Answers


Not sure why you want to do it explicitly. After parsing, it should already be returning date 2014. If you really want to implement, you can try following:

for (String formatString : formatStrings) {
        try {
            iceDate =
                    new SimpleDateFormat(formatString).parse(stringValue);
            System.out.println(iceDate.toString());
            if (formatString.equals("dd-MM-yy")) {
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(iceDate);
                calendar.set(Calendar.YEAR, 2014);//Here you can write your logic to prepend 20 or adding 2000 to 14 (yy) i.e. (2000 + 14)
                iceDate = calendar.getTime();
            }
            return iceDate;
        } catch (ParseException e) {
            logger.warn("##$$$$$### Error in invoice inside convertStringToDate method : ##$$$$$$#### " +
                        ErrorUtility.getStackTraceForException(e));

        }
    }

Need Your Help

Error when going into new activity Android

java android eclipse android-activity settings

I'm trying to start new settings activity. Unfortunately I got these errors: