sloppycode.net
Date formatting
Formatting the date in Java/Servlets.
Home
›
Code snippets
›
Java
›
Date formatting
This servlet shows a simple example of formatting the date and time, using the SimpleDateFormat class.
package sloppycode; import java.io.*; import javax.servlet.*; import java.util.*; import javax.servlet.http.*; import java.text.*; public class DateExample extends HttpServlet { public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); /* Make up date + time */ SimpleDateFormat dFormat = new SimpleDateFormat ("EEEE dd MMMM yyyy - HH:mm:ss a"); Date timeNow = new Date(); String dateTimeString = dFormat.format(timeNow); out.println(dateTimeString); } }
{Name}
Says:
{Date}
{Text}
› Home
› C#
› Snippets
› Articles
› Tools
› Taglines
› ASP
› Dictionary Object
› FSO
› Unix cheat sheet
› Gaming
› CSS
› Yak
› Umbraco
› About
› Contact
› Privacy
› Projects
› Search
› Sitemap
Buy on Amazon
Buy on Amazon
Buy on Amazon
Buy on Amazon