SimpleDateFormat is a concrete class for formatting and parsing dates in a locale-sensitive manner. SimpleDateFormat allows you to start by choosing any user-defined patterns for date-time formatting.
Let us modify the above example as follows −
Example
<%@ page import = "java.io.*,java.util.*" %> <%@ page import = "javax.servlet.*,java.text.*" %> <html> <head> <title>Display Current Date & Time</title> </head> <body> <center> <h1>Display Current Date & Time</h1> </center> <% Date dNow = new Date( ); SimpleDateFormat ft = new SimpleDateFormat ("E yyyy.MM.dd 'at' hh:mm:ss a zzz"); out.print( "<h2 align=\"center\">" + ft.format(dNow) + "</h2>"); %> </body> </html>
Compile the above servlet once again and then call this servlet using the URL https://localhost:8080/CurrentDate. You will receive the following result −
Output
Display Current Date & Time Mon 2010.06.21 at 10:06:44 PM GMT+04:00