In the application I am developing, I need to convert java.time.Instant
object to java.sql.Timestamp
. When I create Instant
object lik
During saving a record to SQL Server DB I faced with the same problem. I've used java.sql.Timestamp.valueOf(String s)
to get Timestamp in UTC:
import java.time.Instant;
import java.time.format.DateTimeFormatter;
....
....
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").withZone(UTC);
String dateTime = dateTimeFormatter.format(Instant date);
Timestamp timestamp = Timestamp.valueOf(dateTime);
It works for me.