Add the Number of Days in the Date in JSTL

JSTL (JSP Standard Tag Library) is a good way to code in JSP pages. JSTL reduce the use of scriptlet and increase efficiency.
<fmt:setLocale value=”en_US” />
<fmt:parseDate type=”both” value =”2018-03-31 00:00:00.000″ var=”var” pattern=”yyyy-MM-dd HH:mm:ss” />
<c:set var=”now” value=”${var}” />
<c:set target=”${now}” property=”time” value=”${now.time + 86400000 * 4}” />
<fmt:formatDate value=”${now}” pattern=”yyyy-MM-dd HH:mm:ss” />
Line number 1: Declaration of Locale
Line number 2 : 
Type can be time or date or both: For now, we are taking Both
Value is the given input: For now, we are taking 2018-03-31 00:00:00.000
var is just a variable name for future use
Pattern: Which pattern you want to give in value, For now, we are taking “yyyy-MM-dd HH:mm:ss”
Line number 3: We just set var variable to a new variable “now”
Line number 4: Now we adding a number of days in the given time. 8640000 is the milliseconds in a day.
Line number 5: Now we give pattern in which we want to show the modified date.
Thanks for the reading post. I hope you like and understand the post. If you have any doubt regarding this post please comment below.

Leave a comment

Your email address will not be published. Required fields are marked *

0 0 0