E
E
Evgeny Krasnov2020-10-19 18:48:59
MySQL
Evgeny Krasnov, 2020-10-19 18:48:59

How to write current date UTC+0 Instant.now() to database?

Greetings dear forum users.

I get the current date UTC+0

Instant instant = Instant.now();
System.out.println(instant);


Next, you need to write the received current date to the database. When trying to write this atu to the database, an error occurs: I searched the entire Internet and it does not work. I don't know how to do it right, please tell me.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Roo, 2020-10-19
@Favorskij

It is necessary to serialize the Instance object into something digestible for the database. In a string, in sql.Date ....
By default, it is serialized to BLOB - therefore it does not fit (I would also try, at least for the sake of experiment, to change the type of the field).

D
Dmitry Shitskov, 2020-10-19
@Zarom

Instant instant = Instant().now().truncatedTo( ChronoUnit.MICROSECONDS ) ;

So I think it will fit
Answer from https://stackoverflow.com/a/47226852

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question