-4

I am trying to set on context object through setter method. But i am getting an error for the line of code below :

IllegalArgumentException: cannot format given Object as a Date

contextBO.setSettlDate(
    new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS")
        .format( nppRequest.getIntrBankSettlementDt().toString())
);

value coming from nppRequest.getIntrBankSettlementDt() is "2016-04-14", Can you guys please help me out here.

n00dl3
  • 21,213
  • 7
  • 66
  • 76
Raj
  • 15
  • 1
  • 3
  • 2
    Debug to find the value of `nppRequest.getIntrBankSettlementDt().toString()` and then try for format it with your pattern. – Naman Sep 28 '17 at 09:22
  • The `format` method accepts a `java.util.Date`, not a `String` –  Sep 28 '17 at 09:28
  • Possible duplicate of [Change the format of Date Java](https://stackoverflow.com/questions/18628059/change-the-format-of-date-java) – Ori Marko Sep 28 '17 at 09:41

2 Answers2

3

(1) From the SimpleDateFormat and your input:

nppRequest.getIntrBankSettlementDt() is "2016-04-14"

The format to be used should be:

new SimpleDateFormat("yyyy-MM-dd")

(2) Also assuming nppRequest.getIntrBankSettlementDt() being a Date, you need not convert it into a String.


And since need in the format "yyyy-MM-dd HH-mm-ss", follow (2) above as:

contextBO.setSettlDate(
   new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS")
      .format( nppRequest.getIntrBankSettlementDt())
JorgeAmVF
  • 1,660
  • 3
  • 21
  • 32
Naman
  • 27,789
  • 26
  • 218
  • 353
0

Hope it will help you out

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
    contextBO.setSettlDate(dateFormat.format( nppRequest.getIntrBankSettlementDt()));
Jay
  • 199
  • 1
  • 14