code_junkie

In JSTL/JSP, given a java.util.Date, how do I find the next day?

Nov 10th, 2011
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. public static Date addDay(Date date){
  2. //TODO you may want to check for a null date and handle it.
  3. Calendar cal = Calendar.getInstance();
  4. cal.setTime (date);
  5. cal.add (Calendar.DATE, 1);
  6. return cal.getTime();
  7. }
  8.  
  9. <?xml version="1.0" encoding="UTF-8" ?>
  10. <taglib xmlns="http://java.sun.com/xml/ns/j2ee"
  11. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  12. xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
  13. version="2.0">
  14. <description>functions library</description>
  15. <display-name>functions</display-name>
  16. <tlib-version>1.1</tlib-version>
  17. <short-name>xfn</short-name>
  18. <uri>http://yourdomain/functions.tld</uri>
  19. <function>
  20. <description>
  21. Adds 1 day to a date.
  22. </description>
  23. <name>addDay</name>
  24. <function-class>Functions</function-class>
  25. <function-signature>java.util.Date addDay(java.util.Date)</function-signature>
  26. <example>
  27. ${xfn:addDay(date)}
  28. </example>
  29. </function>
  30. </taglib>
  31.  
  32. Calendar cal = Calendar.getInstance();
  33. cal.setTime (date);
  34. cal.add (Calendar.DATE, 1);
  35. date = cal.getTime ();
  36.  
  37. // Date d given
  38. d.setTime(d.getTime()+86400000);
Add Comment
Please, Sign In to add comment