I have to do display time with opportunity to edit it.
I used Mysql DB and this columns has date type.
But some trouble is that it is displayed DATE TIME
:
2014-04-02 00:00:00.0
It looks at browser:
I want to truncate time.
Here is snippet from jsp:
<head>
<title>Project info</title>
<jsp:include page="header.jsp" />
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.9.1.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<script>
$(function() {
$("#startDate").datepicker();
$("#endDate").datepicker();
});
</script>
</head>
// ...
<td>${task.startDate}</td>
<td>${task.endDate}</td>
And snippet with edit options:
<div class="form-group">
<span><fmt:message key="task.start"/></span>
<input class="form-control" placeholder="<fmt:message key="task.start"/>"
name="start_date-${task.taskId}" id="startDate" type="date"
value="${task.startDate}"/>
</div>
<div class="form-group">
<span><fmt:message key="task.end"/></span>
<input class="form-control" placeholder="<fmt:message key="task.end"/>"
name="end_date-${task.taskId}" id="endDate" type="date"
value="${task.endDate}"/>
</div>
I easy extract it as property.
At servlet side it is parsed:
Task task = taskService.getByID(id);
String name = (!ValidationUtils.isNullOrEmpty(request.getParameter("name-" + id)))
? request.getParameter("task_name-" + id) : task.getTitle();
String description = (!ValidationUtils.isNullOrEmpty(request.getParameter("task_description-" + id)))
? request.getParameter("task_description-" + id) : task.getDescription();
String state = request.getParameter("state-" + id);
int estimateTime = (request.getParameter("estimate_time-" + id) != null)
? Integer.parseInt(request.getParameter("estimate_time-" + id))
: task.getEstimateTime();
Date startDate = (request.getParameter("start_date-" + id) != null)
? new SimpleDateFormat(DATE_FORMAT).parse(request.getParameter("start_date-" + id))
: task.getStartDate();
Date endDate = (request.getParameter("end_date-" + id) != null)
? new SimpleDateFormat(DATE_FORMAT).parse(request.getParameter("end_date-" + id))
: task.getStartDate()
private static final String DATE_FORMAT = "yyyy-mm-dd";
How to correct view of date and make next input pattern yyyy-mm-dd
?