java.time.instant

java.time.LocalDate vs Instant for a 'business date'

爱⌒轻易说出口 提交于 2020-01-06 06:50:01
问题 I want to represent a 'business date', eg a transaction that happened 'on 3 June 2019'. We actively ignore timezones for this purpose, in full knowledge that 'on 3 June 2019' in Japan might be 'on 2 June 2019' in the US - and ordering within the 'day' is equally irrelevant. All dates will be today, or prior dates. My obvious answer is that this is a LocalDate . However someone else has suggested this would be better represented as an Instant of 2019-06-03T00:00:00.000Z . Apart from the

java.time.LocalDate vs Instant for a 'business date'

邮差的信 提交于 2020-01-06 06:49:36
问题 I want to represent a 'business date', eg a transaction that happened 'on 3 June 2019'. We actively ignore timezones for this purpose, in full knowledge that 'on 3 June 2019' in Japan might be 'on 2 June 2019' in the US - and ordering within the 'day' is equally irrelevant. All dates will be today, or prior dates. My obvious answer is that this is a LocalDate . However someone else has suggested this would be better represented as an Instant of 2019-06-03T00:00:00.000Z . Apart from the

Mapstruct LocalDateTime to Instant

跟風遠走 提交于 2020-01-03 20:59:46
问题 I am new in Mapstruct. I have a model object which includes LocalDateTime type field. DTO includes Instant type field. I want to map LocalDateTime type field to Instant type field. I have TimeZone instance of incoming requests. Manually field setting like that; set( LocalDateTime.ofInstant(x.getStartDate(), timeZone.toZoneId()) ) How can I map these fields using with Mapstruct? 回答1: You have 2 options to achieve what you are looking for. First option: Use the new @Context annotation from 1.2

java.time.Instant.plus(long amountToAdd, TemporalUnit unit) Unsupported unit

女生的网名这么多〃 提交于 2019-12-11 17:13:32
问题 I trying to add few years to current time. My code looks like: // ten yeas ago int backYears = 10; Instant instant = ChronoUnit.YEARS.addTo(Instant.now(), -backYears); But I got an exception: java.time.temporal.UnsupportedTemporalTypeException: Unsupported unit: Years at java.time.Instant.plus(Instant.java:862) When I opened the method Instant.plus I see the following: @Override public Instant plus(long amountToAdd, TemporalUnit unit) { if (unit instanceof ChronoUnit) { switch ((ChronoUnit)

How to store a Java Instant in a MySQL database

孤人 提交于 2019-12-04 21:26:06
问题 With Java Date objects the easiest way to go was to store them as MySql DateTime objects (in UTC). With the switch to Instant this approach won't work anymore because MySQL DateTime does not offer the precision to store nanoseconds. Just truncating them could lead to unexpected comparison results between a newly created Instant objects and the ones read from the database. BigDecimal timestamps don't strike me as an elegant solution: writing select queries manually becomes more difficult

Why JPA does not support java.time.Instant?

纵饮孤独 提交于 2019-12-04 16:29:27
问题 I think that java.time.Instant is the best choice to store a date into DB: it is the most likely TIMESTAMP and you are not depending by timezone, it is just a moment on the time. JPA supports LocalDate , LocalTime , LocalDateTime etc. but not Instant. Sure, you can use either AttributeConverter or some libraries like Jadira but why it isn't supported out of the box? 回答1: I'll try this again. There is some discussion in the issue. The latest discussion seems to be: mkarg said: While that is

Why JPA does not support java.time.Instant?

允我心安 提交于 2019-12-03 23:50:06
I think that java.time.Instant is the best choice to store a date into DB: it is the most likely TIMESTAMP and you are not depending by timezone, it is just a moment on the time. JPA supports LocalDate , LocalTime , LocalDateTime etc. but not Instant. Sure, you can use either AttributeConverter or some libraries like Jadira but why it isn't supported out of the box? Pace I'll try this again. There is some discussion in the issue . The latest discussion seems to be: mkarg said: While that is absolutely correct, the technical answer is a bit more complex: What is the final predicate that makes a