1

I've been getting datetime value from the database. It's working fine but the value the is showing has a .0 on the end. Something like this:

"2018-10-12 12:17:36.0"

This is my code:

<c:foreach items="${paymentInfo}" var="payment">
    ${payment.date_paid}
</c:foreach>

I tried the format date from this answer and received this error:

javax.el.ELException: Cannot convert [2018-11-02 15:21:27.0] of type [class java.lang.String] to [class java.util.Date]

So I don’t believe this question is a duplicate of that one.

This is the database:

enter image description here

enter image description here

Ole V.V.
  • 81,772
  • 15
  • 137
  • 161
trumanblack1025
  • 471
  • 2
  • 8
  • 19
  • the possible duplicate does not help me – trumanblack1025 Oct 25 '18 at 02:09
  • You will need to explain that, trumanblack. Did you try [the answer by BalusC](https://stackoverflow.com/a/6162507/5772882), for example? What happened? Your question can be reopened if you explain how it differs from the previous question. Please add your explanation as an edit in your question. Feel free to ping me with a comment here when you have done so. – Ole V.V. Oct 25 '18 at 07:54
  • @OleV.V. I did the format date and I received this error "javax.el.ELException: Cannot convert [2018-11-02 15:21:27.0] of type [class java.lang.String] to [class java.util.Date]" – trumanblack1025 Oct 26 '18 at 07:44
  • 2
    You're doing it wrong. Apparently, you reading dates stored in your database, but you're reading them as Strings and storing them in date_paid as a String. And then you complain because the string is not in the desired format. You can't format a String. You can format a Date. So you could first parse the String back to a Date, and then format that Date to another format. But the correct fix would be to read the date in the database as a date in the first place, and then to format that date the way you want to. date_paid should be a Date, not a String (and it should be named datePaid) – JB Nizet Oct 26 '18 at 07:59

0 Answers0