0

I have a column in my database that is of type DATE. I inserted the date via Java using the method: Date.valueOF(LocalDate.now()).

r.setRkd(Date.valueOf(LocalDate.now()));

The entry is correct because the exact date appears in the table.

    rkd
------------
 2022-03-02

The problem is that when I call the service I don't get the correct date back in the JSON, but a series of numbersenter code here.

"rkd": 1646175600000

Do you know how I can print the correct date in my JSON? Thank you in advance.

Ole V.V.
  • 81,772
  • 15
  • 137
  • 161
Franky
  • 11
  • 1
  • 1
    It's coming back as a UNIX timestamp with millisecond precision, so you want to find a datetime constructor that can handle such an input. – snakecharmerb Jul 16 '22 at 14:53
  • Since you can use `LocalDate` from the modern Java date and time API, I suggest you don’t also use the old and poorly designed `java.sql.Date`. java.time gives you everything you want, and your JDBC driver should support it too. See [Insert & fetch java.time.LocalDate objects to/from an SQL database such as H2](https://stackoverflow.com/questions/43039614/insert-fetch-java-time-localdate-objects-to-from-an-sql-database-such-as-h2). – Ole V.V. Jul 24 '22 at 08:50

1 Answers1

1

That number you are getting is the milliseconds equivalent to the date you have stored. As far as I know, dates, in general, are stored as milliseconds and displayed in different formats, e.g. YYYY-MM-DD

If you need to display it in date format there should be a method to do it depending on the specific language that you're using.

Hamed
  • 5,867
  • 4
  • 32
  • 56
coses
  • 36
  • 6
  • Thank you so much for your help @coses and @snakecharmerb !! I used a method that converted my Date in LocalDate. Now I have an array, but I can convert it simply! Thank you again!! ``` – Franky Jul 16 '22 at 15:11