title: How to use LocalDateTime
body: <p>what is the right way to solve LocalDateTime error?</p>
  
  <p>I am new to spring therefore I have tried to look for the way to solve this online but I cannot get around it.</p>
  
  <p>This is my entity</p>
  
  <pre><code>package com.reserve.entities;
  
  import java.time.LocalDateTime;
  import java.util.Date;
  
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import org.springframework.format.annotation.DateTimeFormat;
  import org.springframework.format.annotation.DateTimeFormat.ISO;
  
  @Entity
  public class Flight extends AbstractEntity {
  
  
      private String flightNumber;
      private String operatingAirlines;
      private String departureCity;
      private String arrivalCity;
  
  
      @DateTimeFormat(iso=ISO.DATE)
      private Date dateOfDeparture;
  
  
      @Column(name="estimatedDepartureTime",columnDefinition="TIMESTAMP")      
      private LocalDateTime estimatedDepartureTime;
  
      public String getFlightNumber() {
          return flightNumber;
      }
      public void setFlightNumber(String flightNumber) {
          this.flightNumber = flightNumber;
      }
      public String getOperatingAirlines() {
          return operatingAirlines;
      }
      public void setOperatingAirlines(String operatingAirlines) {
          this.operatingAirlines = operatingAirlines;
      }
      public String getDepartureCity() {
          return departureCity;
      }
      public void setDepartureCity(String departureCity) {
          this.departureCity = departureCity;
      }
      public String getArrivalCity() {
          return arrivalCity;
      }
      public void setArrivalCity(String arrivalCity) {
          this.arrivalCity = arrivalCity;
      }
      public Date getDateOfDeparture() {
          return dateOfDeparture;
      }
      public void setDateOfDeparture(Date dateOfDeparture) {
          this.dateOfDeparture = dateOfDeparture;
      }
  
      public LocalDateTime getEstimatedDepartureTime() {
          return estimatedDepartureTime;
      }
      public void setEstimatedDepartureTime(LocalDateTime estimatedDepartureTime) {
          this.estimatedDepartureTime = estimatedDepartureTime;
      }
      @Override
      public String toString() {
          return "Flight [flightNumber=" + flightNumber + ", operatingAirlines=" + operatingAirlines + ", departureCity="
                  + departureCity + ", arrivalCity=" + arrivalCity + ", dateOfDeparture=" + dateOfDeparture
                  + ", estimatedDepartureTime=" + estimatedDepartureTime + "]";
      }   
  
  }
  
  </code></pre>
  
  <p>This is my controller.</p>
  
  <p>I am not sure which information is required.</p>
  
  <p>Please let me know if there are more information that could help.</p>
  
  <pre><code>
  package com.reserve.controllers;
  
  import java.util.Date;
  import java.util.List;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.format.annotation.DateTimeFormat;
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.Model;
  import org.springframework.web.bind.annotation.ModelAttribute;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import org.springframework.web.bind.annotation.RequestParam;
  
  import com.reserve.entities.Flight;
  import com.reserve.repository.FlightRepository;
  
  @Controller
  public class FlightController {
  
      @Autowired
      private FlightRepository flightRepository;
  
      @RequestMapping("findFlights")
      public String findFlights(
              @RequestParam("from")String from, 
              @RequestParam("to")String to, 
              @RequestParam("departureDate")
              @DateTimeFormat(pattern = "MM-dd-yyyy")
              Date departureDate,
              Model model) 
      {
          List&lt;Flight&gt; flights = flightRepository.findFlights(from,to,departureDate);
  
          model.addAttribute("flights", flights);
          return "displayFlights";
      }
  
      @RequestMapping("/ourFlights")
      public String ourFlights() {
          return "ourFlights";
      }
  
      @RequestMapping(value="/add", method=RequestMethod.POST)
      public String addFlights(@ModelAttribute("flight")Flight flight,Model model) {
          Flight save = flightRepository.save(flight);
          String msg = save.getFlightNumber() + " from " + save.getDepartureCity() + " to "
                  + save.getArrivalCity() + " has been added.";
          model.addAttribute("msg", msg);
          return "ourFlights";
      }
  }
  
  </code></pre>
  
  <p>This is my JSP file</p>
  
  <pre><code>
  &lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
      pageEncoding="ISO-8859-1"%&gt;
       &lt;%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%&gt;
  &lt;%@page isELIgnored="false"%&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta charset="ISO-8859-1"&gt;
  &lt;title&gt;Money Wise&lt;/title&gt;
  &lt;link rel="stylesheet" href="/reserve/css/bootstrap.min.css"/&gt;
  &lt;link rel="stylesheet" href="/reserve/css/custom.css"/&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div class="container"&gt;
      &lt;div id="body"&gt;
          &lt;nav class="navbar navbar-expand-lg navbar-light bg-lights"&gt;
            &lt;button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation"&gt;
              &lt;span class="navbar-toggler-icon"&gt;&lt;/span&gt;
            &lt;/button&gt;
            &lt;div class="collapse navbar-collapse" id="navbarNav"&gt;
              &lt;ul class="navbar-nav"&gt;
                &lt;li class="nav-item active"&gt;
                  &lt;a class="nav-link" href="home"&gt;Home &lt;span class="sr-only"&gt;(current)&lt;/span&gt;&lt;/a&gt;
                &lt;/li&gt;
                &lt;li class="nav-item"&gt;
                  &lt;a class="nav-link" href="#"&gt;About&lt;/a&gt;
                &lt;/li&gt;
                &lt;li class="nav-item"&gt;
                  &lt;a class="nav-link" href="#"&gt;Ideology&lt;/a&gt;
                &lt;/li&gt;
                &lt;li class="nav-item"&gt;
                  &lt;a class="nav-link" href="#"&gt;Faq&lt;/a&gt;
                &lt;/li&gt;
                 &lt;li class="nav-item"&gt;
                  &lt;a class="nav-link" href="#"&gt;News&lt;/a&gt;
                &lt;/li&gt;
              &lt;/ul&gt;
              &lt;form class="form-inline my-2 my-lg-0 pull-right"&gt;
                &lt;input class="form-control mr-sm-2" type="search" placeholder="Search"&gt;
                &lt;button class="btn btn-outline-success my-2 my-sm-0" type="submit"&gt;Search&lt;/button&gt;
              &lt;/form&gt;
            &lt;/div&gt;
          &lt;/nav&gt;
          &lt;!-- Site Body --&gt;
          &lt;div  id="content" class="container"&gt;
              &lt;div class="row"&gt;
  
                  &lt;div id="leftMain" class="col-sm-3"&gt;
                  &lt;img src="/reserve/images/jim.png"width=100%/&gt;
  
                  &lt;/div&gt;
                  &lt;div id="mainBody" class="col-sm-9 "&gt;
                      &lt;h2&gt;Add Flights&lt;/h2&gt;
  
                      &lt;form action="add" method="post"&gt;
                          &lt;div class="form-group"&gt;
                              &lt;label for="flightNumber"&gt;Flight number&lt;/label&gt;
                              &lt;input type="text" class="form-control" name="flightNumber" placeholder="Flight number"/&gt;
                          &lt;/div&gt;
                          &lt;div class="form-group"&gt;
                              &lt;label for="operatingAirlines"&gt;Operating airlines&lt;/label&gt;
                              &lt;input type="text" class="form-control" name="operatingAirlines" placeholder="Operating airlines"/&gt;
                          &lt;/div&gt;
                          &lt;div class="form-group"&gt;
                              &lt;label for="departureCity"&gt;Departure city&lt;/label&gt;
                              &lt;input type="text" class="form-control" name="departureCity" placeholder="Departure city"/&gt;
                          &lt;/div&gt;
                          &lt;div class="form-group"&gt;
                              &lt;label for="arrivalCity"&gt;Arrival city&lt;/label&gt;
                              &lt;input type="text" class="form-control" name="arrivalCity" placeholder="Arrival city"/&gt;
                          &lt;/div&gt;
  
                          &lt;div class="form-group"&gt;
                              &lt;label for="dateOfDeparture"&gt;Date of departure&lt;/label&gt;
                              &lt;input type="Date" class="form-control" name="dateOfDeparture" placeholder="Date of departure"/&gt;
                          &lt;/div&gt;
  
                          &lt;div class="form-group"&gt;
                              &lt;label for="estimatedDepartureTime"&gt;Estimated departure time&lt;/label&gt;
                              &lt;input type="datetime-local" class="form-control" name="estimatedDepartureTime" placeholder="Estimated departure time"/&gt;
                          &lt;/div&gt;
                          &lt;button type="submit" class="btn btn-primary"&gt;Save&lt;/button&gt;
                      &lt;/form&gt;
  
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
  &lt;/div&gt;
      &lt;!-- JS, Popper.js, and jQuery --&gt;
  &lt;script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"&gt;&lt;/script&gt;
  &lt;script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"&gt;&lt;/script&gt;
  &lt;script src="/reserve/js/bootstrap.min.js"&gt;&lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>This is the error I get</p>
  
  <pre><code>
  Field error in object 'flight' on field 'estimatedDepartureTime': rejected value [2020-06-20T17:35]; codes 
  
  [typeMismatch.flight.estimatedDepartureTime,typeMismatch.estimatedDepartureTime,typeMismatch.java.time.LocalDateTime,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: 
  
  codes [flight.estimatedDepartureTime,estimatedDepartureTime]; arguments []; default message [estimatedDepartureTime]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.time.LocalDateTime' for property 'estimatedDepartureTime'; 
  
  nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type
  
   [java.lang.String] to type [@javax.persistence.Column java.time.LocalDateTime] for value '2020-06-20T17:35'; nested exception is java.lang.IllegalArgumentException: Parse attempt failed for value [2020-06-20T17:35]]]
  
  ``````
  </code></pre>