Questions tagged [localdate]

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.

656 questions
105
votes
6 answers

How to convert from Instant to LocalDate

I have an Instant coming from a source that should, according to the specs, be a LocalDate, but don't see any methods in the LocalDate class to convert the Instant to a LocalDate. What is the best way to do this?
JL Gradley
  • 1,731
  • 4
  • 14
  • 15
53
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,…
La Carbonell
  • 1,976
  • 5
  • 22
  • 52
37
votes
6 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.
Anna
  • 383
  • 1
  • 3
  • 4
34
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) -…
user5620472
  • 2,722
  • 8
  • 44
  • 97
33
votes
4 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…
MOZAKATAK
  • 483
  • 1
  • 7
  • 14
28
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…
Asier Pomposo
  • 549
  • 4
  • 9
  • 20
22
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
21
votes
6 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…
Michael
  • 236
  • 1
  • 2
  • 6
19
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…
gstackoverflow
  • 36,709
  • 117
  • 359
  • 710
18
votes
1 answer

LocalTime.MIDNIGHT vs. LocalTime.MIN - is there any difference?

I recently answered some questions using LocalDate.atStartOfDay() and LocalDate.atTime(LocalTime.MIN). I was wondering why there is no LocalDate.atEndOfDay() or similar, so one has to use LocalDate.atTime(LocalTime.MAX) in order to get the very last…
deHaar
  • 17,687
  • 10
  • 38
  • 51
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…
Daniel Centore
  • 3,220
  • 1
  • 18
  • 39
17
votes
3 answers

Unknown pattern letter: T - Parse string date with pattern T to LocalDateTime

I need to parse the following date format in String to Java LocalDateTime. So I get date as String like this: 2019-09-20T12:36:39.359 I have the following unit test: @Test public void testDateTime() { assertEquals(SomeObject.getLocalDate(),…
M06H
  • 1,675
  • 3
  • 36
  • 76
17
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()); …
Lukas Forst
  • 802
  • 1
  • 8
  • 25
14
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" :…
Shubham Pandey
  • 1,788
  • 2
  • 18
  • 24
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(),…
Phobos
  • 1,568
  • 10
  • 18
1
2 3
43 44