ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel
  • »
  • Technology»
  • Computers & Software»
  • Computer Software

Date Parsing And Date Formatting In JSP Using JSTL

Updated on September 3, 2016

I have faced problem and i found solution after lots of googling. So may be this will help others when they faced this kind of requirement.

Many times we come across a situation where we want to create java.util.Date object in JSP with the String date. JSTL provides you parseDate tag for parsing the date string and creating date object.

First you have to add formatting tag lib into your project.

put <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%> on the top of your JSP.

Say you have date string in a variable dateStr. Then to make date object out of it you have to write following code.

<fmt:parseDate var="dateObj" value="${dateStr}" type="DATE" pattern="yyyy-MM-dd"/>

This will parse the given date string with the given pattern and create java.util.Date object. you can access the date object with the variable name you have provided in var attribute.

If you want to format the date object then you can use formatDate tag.

<fmt:formatDate value="${dateObj}" pattern="MMM dd, yyyy"/>

Note: For pattern string please check java website.

tag will print the formatted date on the page. So no need to put this into tag.

You can also use var attribute to store formatted string into variable.

Have u ever used ibotta app for rebate? Try it..Use aydtcuy and you will be added to my team, we can earn fast by making team and generating bonus..Worth it..

© 2009 chirag272003

Comments

    0 of 8192 characters used
    Post Comment

    • profile image

      Dread 2 years ago

      You need required jar files for fmt prefix to work in your jsp

    • profile image

      Dona 4 years ago

      I am getting The absoulte uri: http://java.sun.com/jsp/jstl/fmt cannot be resolved in either web.xml or the jar files deployed with this application

      Please clarify what i want to do

      Thanks & regards

      Dona

    • profile image

      Srinivas Reddy 5 years ago

      Great! this helped us very much. Thanks for this.

    • profile image

      Rohan 5 years ago

      This helped me !