I develop a SonarQube plugin and for one of my needs I need to store the analysis date of a project as an SQL TIMESTAMP
(Please note: a TIMESTAMP
, and not a TIMESTAMP WITH TIMEZONE
).
Here is how I currently do it:
// In the SonarQube Sensor
// .getAnalysisDate() returns a java.util.Date
final Instant instant = module.getAnalysisDate().toInstant();
// Timestamp at UTC from the Instant
final LocalDateTime dt = LocalDateTime.frominstant(instant, ZoneOffset.UTC);
final Timestampt ts = Timestamp.valueOf(dt);
I have a little trouble grasping the concept of an Instant, there is also ZonedDateTime etc...
Anyway, this seems to do what I want, but is it the correct way?