1

I have a method which reads the date that in form of srring and then conver it format in dd-MM-yy and finally return a string as shown below..

public static String getSimpleDate11(String dateString) {
        if (dateString == null) {
            return null;
        }

        DateFormat dfIn = new SimpleDateFormat("yyyy-MM-dd");
        DateFormat dfOut = new SimpleDateFormat("dd-MM-yy");

        try {
            Date date = dfIn.parse(dateString);
            return dfOut.format(date);
        } catch (ParseException e) {
            throw new RuntimeException(
                    "The date entered is invalid or has incorrect format"
                            + dateString);
        }
    }

now I am calling this method from somewhere as shown below....

String formatteddate = DateUtility.getSimpleDate11(settlementDate);

now please advise how can I change this in java.sql.Date as I want to store the date in java.sql.Date..

java.sql.Date sd ------ here i want tio store the date finally

folks ple\ase advise .

1
  • @boxed__l can you please update the code in my post that will help me to grasp Thanks Commented Mar 22, 2014 at 6:57

1 Answer 1

1

java.sql.Date takes long value in its constructor (irrespective of the date format)

Date date=dfIn.parse(dateString);
new java.sql.Date(date.getTime());

should be equivalent as they represent the same Date object.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.