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.

524 questions
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,089
  • 3
  • 23
  • 47
9
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
  • 665
  • 2
  • 11
  • 27
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
  • 17,626
  • 8
  • 55
  • 78
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…
8
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
  • 315
  • 1
  • 11
8
votes
8 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,127
  • 5
  • 32
  • 62
7
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,493
  • 2
  • 25
  • 45
7
votes
1 answer

Parse week-based-year and week-of-week-based-year without separator character fails

I'm trying to parse a week-based-year and week-of-week-based-year from a string without any separator character. E.g. "201812" (week 12 of year 2018). Like this: DateTimeFormatter formatter = new DateTimeFormatterBuilder() …
fassen
  • 171
  • 9
6
votes
3 answers

How do I parse an ISO-8601 formatted string that contains no punctuation in Java 8?

How could I parse the following String to a LocalDateTime-Object? 20200203092315000000 I always get the following exception but I didn't understand it: java.time.format.DateTimeParseException: Text '20200203092315000000' could not be parsed at index…
Patrick Vogt
  • 738
  • 2
  • 13
  • 29
6
votes
2 answers

Parsing Date in UpperCase to LocalDate

I'm trying to parse the String FEBRUARY 2019 into a LocalDate. This is my approach: LocalDate month = LocalDate.parse("FEBRUARY 2019", DateTimeFormatter.ofPattern("MMMM yyyy")); Or alternatively setting the Locale.US: LocalDate month =…
Evgenij Reznik
  • 16,046
  • 33
  • 87
  • 157
6
votes
2 answers

Date issue in spring boot data rest

I'm having a problem with spring data rest when I'm handling dates. In a brief, it is delaying the date in one day. For example, if I have 1111-11-11 it returns to me 1111-11-10. There are some related post here in SO (ex1, ex2, ex3), but none of…
André Pacheco
  • 1,384
  • 10
  • 19
6
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…
6
votes
1 answer

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
  • 341
  • 1
  • 4
  • 17
6
votes
3 answers

Year changing from negative -509 to a positive 510 in JDBC with H2 Database

-509 vs 510 I am seeing some kind of altered or erroneous data, with the use of JDBC. So I observe using H2 Database version 1.4.196 on Java 8 Update 151. Here is a complete example. Note how we retrieve the date value three times, first as a…
Basil Bourque
  • 218,480
  • 72
  • 657
  • 915
6
votes
4 answers

How to send Date in REST API in POST method

I am trying to build RESTful web service with Spring support. I am getting following exception when I am trying to send POST request. Input: POST http://localhost:8080/InventoryDemo/item In JSON…
Amit Gawali
  • 250
  • 2
  • 3
  • 16
1
2
3
34 35