MySQL Database Time field selected DateTime, if through Java implementation on the JSP page display time is " year-month-day time: minutes " and other formats, then the following code will have different results!
Two variables in the entity class:
Private Timestamp CreateDate; // creation Time Private Date modifydate; // Modification Time
Assign values to two variables in an interface implementation class:
Detail.setcreatedate (Rs.gettimestamp ("CreateDate")); Detail.setmodifydate (Rs.getdate ("modifydate"));
The code after calling through the servlet is as follows:
longnew Date (). GetTime (); New Timestamp (time); Comment.setcreatedate (timestamp);
Comment.setcreatedate (New Timestamp () (New Date (). GetTime ()));//equivalent to the above three lines
comment.setmodifydate (new Date ());
on the JSP page :
class Class= "Center" ><fmt:formatdate value= "${c.modifydate}" pattern= "Yyyy-mm-dd HH:mm:ss"/></td >
Then the CreateDate field can be output in the form of a JSP page, and modifydate only displays the month and day (even if formatting is not a good use!). )。 HH, the uppercase HH is a 24-hour system. The mm of the month must be capitalized, and the lower case shows the number of minutes.
Therefore, if you want to customize the format output date on the JSP page, and the database is DateTime, then you need to use timestamp as the return type of the variable in the Java entity class, so you can implement the requirement!
Http://blog.sina.com.cn/s/blog_6ac4b8d701016twf.html
Read MySQL database datetime display problem on JSP page