jsp - Specific DateFormat -
in jsp getting date in following formatwed jun 03 2015 13:30:40 gmt+0530 (india standard time)"
how create simple date format can convert string date object
simpledateformat sdf=new simpledateformat("what should type here"); date requeststartdate= request.getparameter("starttime");
tried new simpledateformat("eee, d mmm yyyy")
but not working. here of ways formatting not case.
you can use simple date object tostring() method print current date , time follows:
<% date date = new date(); out.print( "<h2 align=\"center\">" +date.tostring()+"</h2>"); %>
simpledateformat allows start choosing user-defined patterns date-time formatting.
<% date dnow = new date( ); simpledateformat ft = new simpledateformat ("e yyyy.mm.dd 'at' hh:mm:ss zzz"); out.print( "<h2 align=\"center\">" + ft.format(dnow) + "</h2>"); %>
the tag used format dates in variety of ways
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <html> <head> <title>jstl fmt:datenumber tag</title> </head> <body> <h3>number format:</h3> <c:set var="now" value="<%=new java.util.date()%>" /> <p>formatted date (1): <fmt:formatdate type="time" value="${now}" /></p> <p>formatted date (2): <fmt:formatdate type="date" value="${now}" /></p> <p>formatted date (3): <fmt:formatdate type="both" value="${now}" /></p> <p>formatted date (4): <fmt:formatdate type="both" datestyle="short" timestyle="short" value="${now}" /></p> <p>formatted date (5): <fmt:formatdate type="both" datestyle="medium" timestyle="medium" value="${now}" /></p> <p>formatted date (6): <fmt:formatdate type="both" datestyle="long" timestyle="long" value="${now}" /></p> <p>formatted date (7): <fmt:formatdate pattern="yyyy-mm-dd" value="${now}" /></p> </body> </html>
Comments
Post a Comment