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
527
votes
4 answers

What's the difference between Instant and LocalDateTime?

I know that: Instant is rather a "technical" timestamp representation (nanoseconds) for computing. LocalDateTime is rather date/clock representation including time-zones for humans. Still in the end IMO both can be taken as types for most…
manuel aldana
  • 15,650
  • 9
  • 43
  • 50
261
votes
7 answers

How to format LocalDate to string?

I have a LocalDate variable called date, when I print it displays 1988-05-05 I need to convert this to be printed as 05.May 1988. How to do this?
Jasko
  • 2,815
  • 2
  • 12
  • 9
140
votes
16 answers

How to use LocalDateTime RequestParam in Spring? I get "Failed to convert String to LocalDateTime"

I use Spring Boot and included jackson-datatype-jsr310 with Maven: com.fasterxml.jackson.datatype jackson-datatype-jsr310 2.7.3 When I try to use…
Kery Hu
  • 5,626
  • 11
  • 34
  • 51
54
votes
5 answers

ThreeTen-Backport error on Android - ZoneRulesException: No time-zone data files registered

I'm using ThreeTen-Backport library for my Android project (because java.time is not yet implemented in android development). When I write LocalDate today=LocalDate.now(); or LocalTime time=LocalTime.now(); I get the following exception: Caused…
Matan Itzhak
  • 2,702
  • 3
  • 16
  • 35
29
votes
1 answer

Joda Time and Java8 Time difference

I'm looking for a solution to calculate the months between two date. I think joda or java8 time can do it. But when I compare them I found something really weird. import java.text.ParseException; import java.text.SimpleDateFormat; import…
Jiaqi
  • 301
  • 2
  • 6
27
votes
4 answers

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

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…
Derek Mahar
  • 27,608
  • 43
  • 124
  • 174
26
votes
3 answers

Create LocalDate Object from Integers

If I already have a date's month, day, and year as integers, what's the best way to use them to create a LocalDate object? I found this post String to LocalDate , but it starts with a String representation of the date.
Greg Valvo
  • 1,069
  • 1
  • 9
  • 13
25
votes
3 answers

Deserializing LocalDateTime with Jackson JSR310 module

I'm using the library described the Jackson Datatype JSR310 page but I'm still having difficulty getting it to work. I have configured the following bean: @Bean @Primary public ObjectMapper objectMapper() { ObjectMapper mapper = new…
Mekswoll
  • 1,355
  • 3
  • 15
  • 35
22
votes
3 answers

How to parse case-insensitive strings with JSR-310 DateTimeFormatter?

JSR-310 has a handy class DateTimeFormatter which allows you to construct a DateTimeFormatter. I particularly like the pattern(String) method - see javadoc However, I hit a problem whereby this is case sensitive --…
amaidment
  • 6,942
  • 5
  • 52
  • 88
20
votes
3 answers

Should I use threeten instead of joda-time

I came across https://blog.joda.org/2009/11/why-jsr-310-isn-joda-time_4941.html. 1) I am currently migrating Java Calendar to joda-time. I was wondering, should I use threeten instead of joda-time? Is threeten production ready? 2) Can threeten…
Cheok Yan Cheng
  • 47,586
  • 132
  • 466
  • 875
19
votes
1 answer

Are java.util.Date and java.util.Calendar deprecated?

It seems that the new java.time API offers everything from java.util.Date and much more. Is there any reason to use java.util.Date when the newer java.time API is there since Java 8? Should java.util.Date and java.util.Calendar be avoided…
Ondrej Bozek
  • 10,987
  • 7
  • 54
  • 70
16
votes
3 answers

Registering JacksonJsonProvider with ObjectMapper + JavaTimeModule to Jersey 2 Client

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…
libnull-dev
  • 881
  • 1
  • 7
  • 19
16
votes
2 answers

jOOQ - support for JSR310

Does jOOQ provide support for JSR310 in combination with PostgreSQL? In particular, I am trying to use the following classes: java.time.Instant java.time.LocalDate java.time.LocalTime java.time.LocalDateTime I am storing in the following data…
Sophia Aceves
  • 187
  • 1
  • 6
15
votes
2 answers

How to abstract away java.time.Clock for testing purposes in Spring

I have a question with regards to the question Time dependent unit tests Let's say I build Spring application which contains service interface and its implementation If I want to change clock in test, I would have to "pollute" production code and…
Patrik Mihalčin
  • 3,341
  • 7
  • 33
  • 68
14
votes
2 answers

Why does the java.time.Clock has zone information?

Why does java.time.Clock has zone information? From the Clock you only can get an Instant when calling the instant() method - which is a time without zone info. Is the only purpose to have the zone available in the clock to e.g. create a…
James
  • 11,654
  • 6
  • 52
  • 81
1
2 3 4 5 6 7 8