How to print current date in JSP?

Viewed 42523

I want to do something like this:

 <?php echo date('Y'); ?>

But then in a .jsp file. All the tutorials I'm seeing require building a class somewhere. We're running appFuse and Tapestry. Surely one of those (if not Java itself) provide us with something to do this sort of thing without all that overhead.

This seems like it should work, but doesn't:

 <%= new Date.getYear() %>
6 Answers

In Java 8 to print year you can use:

<%= LocalDate.now().getYear() %>
<%@page import="java.time.LocalDate"%>

${LocalDate.now().year}
Related