Here is the problem:
@GetMapping("/main/search")
public String search (@RequestParam String departure,
@RequestParam String arrival,
@RequestParam String departureTime,
Model model) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
departureTime+=" 00:00:00";
LocalDateTime date = LocalDateTime.parse(departureTime, formatter);
List<BusFlight> busflights = busFlightService.search(departure, arrival, date);
Format comes like 2015-10-23T03:34:40
When I try to solve problem this way:
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss", Locale.US);
departureTime+=" 00:00:00";
LocalDateTime date = LocalDateTime.parse(departureTime, formatter);
String currentDate = date.format(formatter);
List<BusFlight> busflights = busFlightService.search(departure, arrival, currentDate);
I get problem in another place. Java requires to change type LocalDateTime
to String type in my service calass:
public List<BusFlight> search(String departure, String arrival, **LocalDateTime** departureTime)*
{
*LocalDateTime departureTimeTho = departureTime.**plusDays(1)**;*
And if I change LocalDateTime
to String
, a can't use method plusDays(1) :(((
And I also tried this way:
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss", Locale.US);
departureTime+="T00:00:00";
LocalDateTime date = LocalDateTime.parse(departureTime, formatter);
format comes the same with charater 'T' 2018-09-13T05:42:28
This way also not working for me:
String localTime = "2018-09-13 00:00:00";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH);
LocalDateTime date = LocalDateTime.parse(localTime, formatter);
String replace = date.toString().replace("T", " ");
becuse a cann't change type to String
And this way not working becouse of exception: Unsupported field: OffsetSeconds
String localdatetime = "2011-05-01";
localdatetime+="T00:00:00";
DateTimeFormatter date = DateTimeFormatter.ofPattern("yyyy-MM-ddXXX:mm:ss", Locale.US);
LocalDateTime mzt = LocalDateTime.parse(localdatetime);
System.out.println(mzt.format(date));
Please help! How can I solve the problem?
Please CHECK my SCREENSHOTS for undestanding problem