Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Today's date JSP

Tags:

jsp

I've found myself working on some old JSP and want to do something simple like display today's date in dd/mm/yyyy format

Doesn't seem to be that simple,

So far I've imported java.util.*

And I've tried various things like

String df = new SimpleDateFormat("dd/MM/yy");

However, to no avail...

like image 340
jim smith Avatar asked Nov 17 '25 20:11

jim smith


1 Answers

A cleaner approach is to use JSTL - <fmt:formatDate/> tags.

<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<jsp:useBean id="now" class="java.util.Date"/>    
<fmt:formatDate value="${now}" dateStyle="long"/>
<fmt:formatDate value="${now}" pattern="dd-MM-yyyy HH:mm:ss a z" />
like image 135
KV Prajapati Avatar answered Nov 19 '25 13:11

KV Prajapati



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!