ronan_40060
asked on
Convert Java LocalDate to date time stamp UTC format
My Entity Class AppAuthorization.java has the below column EFFECTIVE_START_DATE which is defined as EFFECTIVE_START_DATE DATE(8) NOT NULL column of APP_AUTHORIZATION Table in H2 DB
My question is how can I save effectiveStartDate in UTC date time stamp format in APP_AUTHORIZATION Table using Java 8 ?
@Column(name = "EFFECTIVE_START_DATE", nullable = false)
private LocalDate effectiveStartDate;
My question is how can I save effectiveStartDate in UTC date time stamp format in APP_AUTHORIZATION Table using Java 8 ?
That's supported out of the box in JPA >= 2.2 and Hibernate >= 5.3 apparently
ASKER
Thank you CEHJ ,
Im using below code to convert LocalDate to UTC datetime Stamp . Is this correct ?
Im using below code to convert LocalDate to UTC datetime Stamp . Is this correct ?
appAuthorization.setEffectiveStartDa te(LocalDa te.now(Zon eOffset.UT C));
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
even I found that Instant.now() can be used to get time in UTC format so which one is better ? This one or above
in my earlier post >
in my earlier post >
appAuthorization.setEffectiveStartDate(LocalDate.from(Instant.now()));
Hmm. I wonder what would happen if the 'system UTC' clock were not available with Instant.now()
ASKER
looks like LocalDate.now(ZoneOffset.U TC) is a better solution
I'd guess, yes
ASKER
is there any way to substract a milli second from
LocalDate.now(ZoneOffset.UTC)