jsr310

Is there a equivalent to ChronoUnit.between that returns fraction instead of integer?

余生颓废 提交于 2021-02-18 22:35:27
问题 Methods such is ChronoUnit.HOURS.between(start, end) returns long so I can't get the fraction from there. Is there an alternative method/approach that would return a fraction? 回答1: The whole point of ChronoUnit.HOURS.between(start, end) is to get the number of HOURS between the two timepoints. For example: it's either 1 or 2 hours between, there is no such thing as 1.5658 hours*. If you need more precicion, use another ChronoUnit, i.e. Minutes or seconds. The problem with decimal fractions is

Java Date and Time: How do I make plus() and until() to be each others inverse

安稳与你 提交于 2020-01-14 12:39:52
问题 Most of the time, these 2 methods are each others inverse: Temporal Temporal.plus(long, TemporalUnit) long Temporal.until(Temporal, TemporalUnit) For example starting from 1-JAN: System.out.println("1-JAN plus 1 month: " + LocalDate.of(2017, 1, 1).plus(1, ChronoUnit.MONTHS)); System.out.println("1-JAN until 1-FEB in months: " + LocalDate.of(2017, 1, 1).until(LocalDate.of(2017, 2, 1), ChronoUnit.MONTHS)); They are each others inverse: 1-JAN plus 1 month: 2017-02-01 1-JAN until 1-FEB in months:

Period with hours, minutes and seconds [closed]

风流意气都作罢 提交于 2020-01-03 10:20:07
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . I have need for an interval data type representing years, months, weeks, days, hours, minutes, seconds. The first three (years, months, days) can be done with Period and the last three (hours, minutes, seconds) can be done with Duration however none of them seem to do both. Ideally I'd like to avoid having to

Registering JacksonJsonProvider with ObjectMapper + JavaTimeModule to Jersey 2 Client

你离开我真会死。 提交于 2019-12-21 04:05:43
问题 I'm trying to marshal response containing ISO formatted timestamp like that: { ... "time" : "2014-07-02T04:00:00.000000Z" ... } into ZonedDateTime field in my domain model object. Eventually it works if I use solution that is commented in following snippet.There are many similar questions on SO but I would like to get a specific answer what is wrong with another approach which uses JacksonJsonProvider with ObjectMapper + JavaTimeModule ? ObjectMapper mapper = new ObjectMapper(); mapper

Jooq LocalDateTime fields use system timezone instead of session timezone

ε祈祈猫儿з 提交于 2019-12-20 04:09:26
问题 I'm using jooq (v3.11.9) to access a MySQL database that is running in UTC time. I've using generated entities and am using JSR-310 time types. The option I'm using in my config: <javaTimeTypes>true</javaTimeTypes> My understanding is that the MySQL datetime and timestamp types both map to LocalDateTime which makes sense as MySQL doesn't store timezone information with the times. However when I run queries on a machine in a different timezone (in my case EST) the dates are all in my local

How can I change Jacksons Configuration when using Spring Data REST?

本秂侑毒 提交于 2019-12-19 12:43:08
问题 I'm trying to configure Jackson to show JSR 310 instants in ISO 8601 format. @Configuration class Jackson { @Bean static ObjectMapper objectMapper() { ObjectMapper objectMapper = new ObjectMapper().findAndRegisterModules(); objectMapper.disable( SerializationFeature.WRITE_DATES_AS_TIMESTAMPS ); return objectMapper; } } However this is not a unique Bean, and realistically I only would like to disable this one setting. So I'm not really wanting to create ObjectMapper, so much as specify a

How to bind a Vaadin DateField to a LocalDateTime

微笑、不失礼 提交于 2019-12-11 02:08:00
问题 The Vaadin docs show how to use the DateField with java.util.Date but I want to bind the DateField with a BeanFieldGroup to a bean property of Java 8 type java.time.LocalDateTime . How can I achieve that? 回答1: Seems like a Vaadin Converter is the way to go: package org.raubvogel.fooddiary.util; import java.time.LocalDateTime; import java.time.ZoneOffset; import java.util.Date; import java.util.Locale; import com.vaadin.data.util.converter.Converter; /** * Provides a conversion between old {

Jackson deserialization issue for ZonedDateTime

与世无争的帅哥 提交于 2019-12-10 04:17:19
问题 I've the following field in a class I use during deserialization of a service that I'm consuming. private ZonedDateTime transactionDateTime; The service I'm consuming may return a Date or DateTime using the pattern: yyyy-MM-dd'T'HH:mm:ss.SSSZ Let me give 2 examples of what the service returns: 2015-11-18T18:05:38.000+0200 2015-11-18T00:00:00.000+0200 While first one works well, the latter causes the following exception to be thrown during deserialization: java.time.format

How do I format a javax.time.Instant as a string in the local time zone?

你说的曾经没有我的故事 提交于 2019-12-09 04:18:15
问题 How do I format a javax.time.Instant as a string in the local time zone? The following translates a local Instant to UTC, not to the local time zone as I was expecting. Removing the call to toLocalDateTime() does the same. How can I get the local time instead? public String getDateTimeString( final Instant instant ) { checkNotNull( instant ); DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder(); DateTimeFormatter formatter = builder.appendPattern( "yyyyMMddHHmmss" ).toFormatter()

Java jsr310: difference between dates and times

杀马特。学长 韩版系。学妹 提交于 2019-12-08 05:19:09
问题 There are a plethora of SO questions that deal with calculating the difference between two dates or two times in Java. Many answers point out the problems with the core Java Date classes, and suggest using Jodatime, but AFAIK, there are none that suggest how to do this using jsr310. So, are there any methods to calculate the difference between two dates or two times in jsr310? For reference, the following questions handle this issue: In core Java: milliseconds between two datetimes In