简体   繁体   中英

Comparing dates in JSTL

I'm a front end programmer that's new to JSTL coding and trying to find out if one date happens before the other.

<fmt:parseDate var="convertedDate" value="${checkDate}" pattern="MM/dd/yyyy" parseLocale="en_US"/>
<c:set var="year2020" value="${<%=new Date("1-1-2019") %>}"
<c:set var="is2019CheckDate" value="${convertedDate < year2020}" />

But this is complaining:

"${<%=new Date("1-2-2019") %>}" contains invalid expression(s): javax.el.ELException: Failed to parse the expression [${<%=new Date("1-2-2019") %>}]

How can I express the new date in JSTL? Thanks for any helpful tips.

How can I express the new date in JSTL?

Same way you parsed the checkDate string:

<fmt:parseDate var="year2020" value="1/1/2019" pattern="M/d/yyyy"/>

Though I don't know why the year 2020 starts at the beginning of 2019.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM