Display and processing of time objects in Java Development

Source: Internet
Author: User
Tags dateformat

As we all know, the time in the database is of the Date type, and the yyyy-mm-dd format is usually displayed on the page, and, JSONObject is often used to transmit time objects from JSP pages to front-end controllers and backend services. JSONObject only supports the String type. Therefore, the storage and retrieval of time objects involve converting Date to String. Suppose our requirement is to get a system time and save it to the Database Table time, And then retrieve it and display it on the page. Then, after the Controller receives the input time from the JSP page, it must convert the time to the String type so that it can be added to the JSONObject and delivered to the background. Yes: Date date = new Date (); DateFormat dateFormat = new impleDateFormat ("yyyy-MM-dd"); String addTime = dateFormat. format (date); time. put ("addTime", addTime) is retrieved from the database and displayed on the page. How can this problem be solved? Similarly, the Controller obtains the result set of the time set through the background service and converts it to the String type to be uploaded to the JSP page for display. DateFormat dateFormat = new impleDateFormat ("yyyy-MM-dd"); String addTime = dateFormat. format (time. getAddTime (); now let's think about how to query this table if the time is used as a column and there are other fields in the table. We get the set of objects through the service. If the table name is courseMappingVO, The courseMappingVOList is returned and uploaded as the result set to the JSP page. How can I display the time properly? Even if the time is not a column in the table, but a unique column in the table, it is not easy to convert in the Controller (of course not difficult to convert) and then transmitted to the JSP page for display. What's more, it is a column in a table, so we have to think about whether the conversion can be performed on the JSP page, so we will not be worried about how to pass the results. The answer is yes: Similarly, the courseMappingVoList is uploaded as the result to the JSP page. The code for displaying the result on the JSP page is as follows: in this way, the time is normally displayed in the format of yyyy-mm-dd. The author's test page is as follows:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.