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]
524 questions
62
votes
6 answers
How to convert from Instant to LocalDate
I have an Instant coming from a source that should, according to the spec, be a LocalDate, but don't see any methods in LocalDate for the conversion. What is the best way to do this?
![](../../users/profiles/3965322.webp)
JL Gradley
- 1,205
- 2
- 11
- 14
40
votes
3 answers
Java 8 – Create Instant from LocalDateTime with TimeZone
I have a date stored in the DB in string format ddMMyyyy and hh:mm and the TimeZone.
I want to create an Instant based on that information, but I don't know how to do it.
something like
LocalDateTime dateTime = LocalDateTime.of(2017, Month.JUNE, 1,…
![](../../users/profiles/7716095.webp)
La Carbonell
- 1,638
- 3
- 17
- 47
22
votes
1 answer
How can I return LocalDate.now() in milliseconds?
I create date now:
ZoneId gmt = ZoneId.of("GMT");
LocalDateTime localDateTime = LocalDateTime.now();
LocalDate localDateNow = localDateTime.toLocalDate();
Then I want return this date in milliseconds:
localDateNow.atStartOfDay(gmt) -…
![](../../users/profiles/5620472.webp)
user5620472
- 2,352
- 5
- 36
- 82
20
votes
5 answers
How to format LocalDate object to MM/dd/yyyy and have format persist
I am reading text and storing the dates as LocalDate variables.
Is there any way for me to preserve the formatting from DateTimeFormatter so that when I call the LocalDate variable it will still be in this format.
EDIT:I want the parsedDate to be…
![](../../users/profiles/3080208.webp)
MOZAKATAK
- 353
- 1
- 4
- 14
19
votes
2 answers
Error java.time.format.DateTimeParseException: could not be parsed, unparsed text found at index 10
I´m trying to pase the next String using LocalDateTime, but I always get de unparsed text found error:
Error java.time.format.DateTimeParseException: Text '2016-08-18 14:27:15.103+02' could not be parsed, unparsed text found at index 10
Here is my…
![](../../users/profiles/4806540.webp)
Asier Pomposo
- 409
- 2
- 7
- 19
18
votes
2 answers
LocalDate.plus Incorrect Answer
Java's LocalDate API seems to be giving the incorrect answer when calling plus(...) with a long Period, where I'm getting an off by one error. Am I doing something wrong here?
import java.time.LocalDate;
import java.time.Month;
import…
![](../../users/profiles/998251.webp)
Daniel Centore
- 2,968
- 1
- 15
- 35
18
votes
5 answers
How make implicit Ordered on java.time.LocalDate
I want to use java.time.LocalDate and java.time.LocalDateTime with an implicit Ordered like:
val date1 = java.time.LocalDate.of(2000, 1, 1)
val date2 = java.time.LocalDate.of(2010, 10, 10)
if (date1 < date2) ...
import…
![](../../users/profiles/4871062.webp)
Michael
- 206
- 1
- 2
- 6
16
votes
3 answers
Different behavior of WeekFields on JVM 8 and JVM 10
I have really simple program here:
public static void main(String[] args) {
LocalDate year = LocalDate.ofYearDay(2022, 100);
System.out.println(year);
System.out.println(WeekFields.of(Locale.GERMAN).weekOfYear());
…
![](../../users/profiles/7169288.webp)
Lukas Forst
- 702
- 1
- 6
- 20
16
votes
1 answer
DateTimeParseException: Text could not be parsed: Unable to obtain LocalDateTime from TemporalAccessor
LocalDateTime.parse("2017-02-02 08:59:12", DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss"));
It prints error:
java.time.format.DateTimeParseException: Text '2017-02-02 08:59:12' could not be parsed: Unable to obtain LocalDateTime from…
![](../../users/profiles/2674303.webp)
gstackoverflow
- 31,683
- 83
- 267
- 574
14
votes
2 answers
How to stop LocalDate from changing when being saved to a mySQL database
When saving a LocalDate field (e.g. '2017-09-27') to a mySQL Date column using JPA CriteriaBuilder API, the result is different (e.g. '2017-09-26').
I have validated that my database's timezone is set to UTC using SELECT TIMEDIFF(NOW(),…
![](../../users/profiles/3832047.webp)
Phobos
- 827
- 5
- 14
13
votes
4 answers
Java: Unable to obtain LocalDate from TemporalAccessor
I am trying to change the format of a String date from EEEE MMMM d to MM/d/yyyy by, first, converting it into a LocalDate and then applying a formatter of a different pattern to the LocalDate before parsing it into String again.
Here's my…
user7049000
12
votes
3 answers
How to fix "Call requires API level 26 (current min is 25) " error in Android
I know this question may be duplicated but I didn't find any answer for my problem, I'm using LocalDateTime in my Android app that requires API 26 and my device's API is 25.
What can I do? Your help will be very appreciated.
![](../../users/profiles/11541955.webp)
Anna
- 133
- 1
- 4
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…
![](../../users/profiles/4244288.webp)
Hengrui Jiang
- 769
- 1
- 8
- 21
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…
![](../../users/profiles/70942.webp)
ant2009
- 30,351
- 141
- 365
- 559
10
votes
1 answer
Deserialize date attribute of json into LocalDate
I am trying to de-serialize date attribute in json of format "2018-05-27" using Gson. I want date to be in LocalDate format after de-serialization.
For json input :
{
"id" : 1,
"name" : "test",
"startDate" : "2018-01-01",
"endDate" :…
![](../../users/profiles/5081033.webp)
Shubham Pandey
- 1,498
- 1
- 15
- 23