LocalDate is part of the java.time package and represents a year-month-day in the ISO calendar and is useful for representing a date without a time, such as 2000-01-01 (January 1st 2000). It can be used for storing a birth date for example.
Questions tagged [localdate]
656 questions
12
votes
1 answer
How do I enable the JSR310 support for LocalDate using Jackson?
I have added the JS310 dependency to Maven and refreshed the dependencies:
com.fasterxml.jackson.datatype
jackson-datatype-jsr310
…

noumenal
- 1,077
- 2
- 16
- 36
12
votes
3 answers
How to convert util.Date to time.LocalDate correctly for dates before 1893
I googled for a while and the most commonly used method seems to be
date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
However, this method seems to fail for dates before 1893-04-01
The following test fails on my machine with an…

Hengrui Jiang
- 861
- 1
- 10
- 23
12
votes
7 answers
Calcuting the date difference for a specified number of days using LocalDate class
I'm using openjdk version 1.8.0_112-release for development but will need to support previous JDK versions too (pre-Java-8) - so can't use java.time.
I am writing a utitily class to calculate the date to see if a saved date is before the current…

ant2009
- 27,094
- 154
- 411
- 609
11
votes
3 answers
Parsing a year String to a LocalDate with Java8
With Joda library, you can do
DateTimeFormat.forPattern("yyyy").parseLocalDate("2008")
that creates a LocalDate at Jan 1st, 2008
With Java8, you can try to do
LocalDate.parse("2008",DateTimeFormatter.ofPattern("yyyy"))
but that fails to…

facewindu
- 705
- 3
- 11
- 31
10
votes
3 answers
LocalDate is serialized as an array
I'm using springBoot to develop a REST APi. And i have a LocalDate field "firstDate" in the response model of a GET endpoint. But this LocalDate is serializable as an array in the response's json!
"firstDate": [
2021,
3,
1
…

Rubis
- 101
- 1
- 3
10
votes
9 answers
How to detect the given date format using java
I have a method that gets a string and change that to a particular date format but the thing is the date will be any format
For Example
16 July 2012
March 20 2012
2012 March 20
So I need to detect the string is in which file format.
I use the…

Ramesh
- 2,295
- 5
- 35
- 64
9
votes
2 answers
Unexpected date calculation result
I have a method to view a calendar in Java that calculates the date by year, day of the week and week-number.
Now when I calculates the dates from 2017 everything works. But when I calculates the dates from January 2018 it takes the dates of year…

JimmyD
- 2,629
- 4
- 29
- 58
9
votes
2 answers
How to compare objects of LocalDate and Calendar class?
I am trying to compare dates from two object having different types. Is there any way to convert Calendar object to LocalDater or vice-versa?
Thank you :)
public class ABC{
public static void main(String args[]){
Calendar c1=…

Maulik Doshi
- 323
- 2
- 11
8
votes
3 answers
Adding Period to startDate doesn't produce endDate
I have two LocalDates declared as following:
val startDate = LocalDate.of(2019, 10, 31) // 2019-10-31
val endDate = LocalDate.of(2019, 9, 30) // 2019-09-30
Then I calculate the period between them using Period.between function:
val period =…

Ilya
- 21,871
- 8
- 73
- 92
8
votes
2 answers
How can I change the language of the months provided by LocalDate?
I need to find the current month and print it. I have the following code:
this.currentDate=LocalDate.now();
this.month = this.currentDate.getMonth();
The problem is that the month is in English and I need to print it in French, to match the rest of…

shas
- 378
- 4
- 20
8
votes
2 answers
JPA: How to convert LocalDateTime to LocalDate
How could I use @NamedQuery to get a coloumn as LocalDate type which is defined LocalDateTime type. How can i do it?

skip
- 12,193
- 32
- 113
- 153
8
votes
1 answer
Mapstruct LocalDateTime to Instant
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…

Batuhan
- 463
- 2
- 6
- 22
8
votes
2 answers
Spring jpa hibernate mysql LocalDate off one day after persist
Whenever I persist LocalDate to MySQL Database, the Date is stored one day off (11 Nov 2017 becomes 10 Nov 2017). I've already tried to set the timezone in the application on MySQL server and set the legacyDateTimeCode to false but the problem still…

Ceryni
- 371
- 1
- 5
- 18
8
votes
2 answers
java.time.LocalDate not supported in native queries by latest Spring Data/Hibernate?
Problem: Native queries with Spring Data returning dates return java.sql.Date not java.time.LocalDate, despite the setup.
Context: A new project with Spring Boot 2.0.0.M5 (the latest), Hibernate 5.2.11, Hibernate-Java8 5.2.12 (which gives support…

wishihadabettername
- 14,231
- 21
- 68
- 85
8
votes
2 answers
Java 8 LocalDate to JavaScript Date
I would like to convert this Java LocalDate to a JavaScript Date:
{
"date": {
"year": 2016,
"month": "NOVEMBER",
"dayOfMonth": 15,
"monthValue": 11,
"dayOfWeek": "TUESDAY",
"era": "CE",
…

OddDev
- 1,521
- 7
- 23
- 45