Questions tagged [jsr310]

JSR 310: Date and Time API in Java JDK 8. Please use the [java-time] tag for questions relating to date & time in Java SE 8.

JSR 310 is the new date and time API added to Java JDK 8 using the package name java.time. More information, backport and related projects are available at the ThreeTen home page.

  • Please avoid using this tag moving forwards
  • Use the tag for questions relating to date & time in Java SE 8
  • Use the tag for questions relating to the backport to Java SE 7
111 questions
5
votes
2 answers

JSR310 Year.parse() throws DateTimeParseException with values < 1000

I'm trying to parse Year String values in the range from 0 to 1000 with java.time.Year.parse(), however parsing fails with java.time.format.DateTimeParseException: Text '999' could not be parsed at index 0. The javadoc of Year.parse states: Obtains…
eidottermihi
  • 212
  • 1
  • 11
5
votes
1 answer

How to save Java 8 Instant to MongoDB as Date type using Spring MongoTemplate?

I have a Java class having an Instant type of member variable: public class SomeRecord { private String someId; private Instant someInstant; // getters and setters } I am using MongoTemplate to update the someInstant field in…
Vikas Prasad
  • 3,163
  • 5
  • 28
  • 39
5
votes
3 answers

Is there official documentation by Oracle saying we should not use java.util.Date in new project

I am writing new project in Java 8 in company. I have suggested to use Java 8 date time API but one of my co workers says that new Date time API works slow. Is it true? Also I want to get some official documentation from Oracle which will mention…
user1321466
  • 1,889
  • 2
  • 21
  • 29
5
votes
4 answers

When the Duration.between() in Java DateTime return negative value

I am preaparing for the Java OCP Test, and in the mock test there is a question about Java DateTime like this: Given that New York is 3 hours ahead of Los Angeles, what will the following code print? LocalDateTime ldt = LocalDateTime.of(2017, 12,…
Ock
  • 1,262
  • 3
  • 18
  • 38
5
votes
1 answer

javax.time in Kotlin

I tried following code to use javax.time in Kotlin: import javax.time.calendar.LocalDate fun main(args: Array){ println("Today is ${LocalDate.now()}"); } And got compilation error: C:\kotlin-hello-world>kotlinc hello.kt -include-runtime…
Joel Handwell
  • 742
  • 1
  • 10
  • 18
5
votes
0 answers

Java-8 LocalDateTime serializing with DateTimeFormatter

I am using Dropwizard 0.8.4 and jackson-datatype-jsr310. a) Would like to serialise my LocalDateTime to JSON output as DateTimeFormatter.ISO_INSTANT but could not find any clean way to do that (without implementing custom serialising classes),…
Render
  • 2,199
  • 2
  • 16
  • 14
4
votes
0 answers

Multiple datasources with Jsr310JpaConverters not work

When there is a LocalDateTime attribute in Entity, serialization fails when using the repository interface query, and when a single data source is working. When I only use the following configuration in application.java, it does not work:…
lvhailong
  • 41
  • 4
4
votes
2 answers

How do I convert a json that contains a LocalDate field to deserializable format?

I have an object stored in a String. One of the object's fields is a LocalDate. "from": { "year": 1000, "month": "JANUARY", "era": "CE", "dayOfMonth": 1, "dayOfWeek": "WEDNESDAY", "dayOfYear": 1, …
naglas
  • 462
  • 1
  • 6
  • 16
4
votes
2 answers

How to bind a Vaadin DateField to a LocalDateTime

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?
Steffen Harbich
  • 2,639
  • 2
  • 37
  • 71
4
votes
1 answer

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

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,…
Geoffrey De Smet
  • 26,223
  • 11
  • 73
  • 120
4
votes
2 answers

Java Date and Time (JSR 310): does a temporal range contain value without iterating all of them

I have a custom range (~ Collection) which has 2 Temporal bounds (from and to) and can enumerate all values between those 2 bounds in time by incrementing with a given TemporalUnit incrementUnitType. private final Temporal_ from; private final…
Geoffrey De Smet
  • 26,223
  • 11
  • 73
  • 120
4
votes
1 answer

'AttributeConverter and explicit Type cannot be applied to same attribute' using LocalDateTime

I am using a ZonedDateTime currently using Spring Boot 1.3.1 with JPA and Hibernate using jadira: @Type(type = "org.jadira.usertype.dateandtime.threeten.PersistentZonedDateTime") private ZonedDateTime startTime; This works fine. However, I would…
Wim Deblauwe
  • 25,113
  • 20
  • 133
  • 211
4
votes
2 answers

ThreeTen and parsing an Instant

I'm using ThreeTen and attempted to format an Instant. Would be easier to just split it but I'm curious, should this work? From everything I've read Instant should be parse-able, and with all the components of the pattern: @Test public void…
user1351848
  • 127
  • 1
  • 1
  • 9
4
votes
2 answers

What will happen when a class shipped with our jar gets added to the Java standard library?

I'm currently thinking about adding a small part of JSR-310, javax.time.Duration to our library. This works perfectly fine currently. But JSR-310 is planned to be integrated in Java 8! When executing our application on Java 8, what will happen if…
soc
  • 27,983
  • 20
  • 111
  • 215
3
votes
3 answers

Find next occurrence of a time, like TemporalAdjuster

Is there anything in JSR-310 for finding the next occurrence of a given time? I'm really looking for the same thing as this question but for times instead of days. For example, starting with a date of 2020-09-17 at 06:30 UTC, I'd like to find the…
DaveyDaveDave
  • 9,821
  • 11
  • 64
  • 77