Tag <fmt:parseDate> dùng để phân tích (parse) chuỗi thành ngày tháng.
Thuộc tính
| Attribute | Description | Required | Default |
|---|---|---|---|
| value | Giá trị ngày cần parse | No | Body |
| type | DATE, TIME, hoặc BOTH | No | date |
| dateStyle | FULL, LONG, MEDIUM, SHORT, DEFAULT | No | Default |
| timeStyle | FULL, LONG, MEDIUM, SHORT, DEFAULT | No | Default |
| parseLocale | Locale dùng khi parse | No | Default locale |
| pattern | Pattern parse tùy chỉnh | No | None |
| timeZone | Múi giờ của ngày parse | No | Default time zone |
| var | Tên biến lưu ngày đã parse | No | Print to page |
| scope | Phạm vi biến lưu ngày | No | page |
Thuộc tính pattern hoạt động như pattern của <fmt:formatDate> nhưng cho parser biết format mong đợi.
Ví dụ
<%@ taglib prefix = "c" uri = "https://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix = "fmt" uri = "https://java.sun.com/jsp/jstl/fmt" %>
<html>
<head> <title>JSTL fmt:parseDate Tag</title> </head>
<body>
<h3>Date Parsing:</h3>
<c:set var = "now" value = "20-10-2010" />
<fmt:parseDate value = "${now}" var = "parsedEmpDate" pattern = "dd-MM-yyyy" />
<p>Parsed Date: <c:out value = "${parsedEmpDate}" /></p>
</body>
</html>
Kết quả:
Date Parsing: Parsed Date: Wed Oct 20 00:00:00 GST 2010