0

I have a spring mvc project and Im displaying event start and end times on a jsp page. The events are stored in my database as localdatetime and I am retrieving them from my database and then displaying them. I am displaying them on my jsp page like this

<c:forEach items="${eventList}" var="events">
<tr>
<td>${events.getId()}</td>
<td>${events.getStart()} - ${events.getEnd()}</td>
</tr>
</c:forEach>

They are displaying like this 2019-04-28T11:30 - 2019-04-28T14:30

Is it possible to display the date and time separately?

EDITED: This is the code for my backend, where i am getting them events from my database

@RequestMapping(value = "/events", method = RequestMethod.GET)
public String getEvents(Model model) {

        List<Event> events = eventService.findAll();
        model.addAttribute("eventList", events);
        return "events";
    }

The problem is how can i display them as the start/end as a separate date and time when they being added to the model as a localdatetime?

Jane Ryan
  • 159
  • 1
  • 1
  • 8

2 Answers2

0

The method split() breaks a string into many substrings using a character. It returns a array with the strings. Example:

String date = 2019-04-28T11:30
String array[] = new String[2]
array = date.split("T");

Now the array is ["2019-04-28","11:30"]. And if you want to split the date

date = array[1]
String array2[] = new String[3]
array2 = date.split("-");

Now the array2 is ["2019","04","28"].

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • Ive edited my question a bit, as I don't think split will work for me. Can i use split on my jsp page side? – Jane Ryan Apr 28 '19 at 11:07
0

Use new Date & Time Api [Java 8].

https://docs.oracle.com/javase/8/docs/api/java/time/LocalDateTime.html#toLocalDate--

LocalDateTime dt = LocalDateTime.now();
System.out.println("Local Date : " + dt.toLocalDate());
System.out.println("Local Date : " + dt.toLocalTime());
Ng Sharma
  • 2,072
  • 8
  • 27
  • 49