Time Control precise to seconds in JSP pages

Source: Internet
Author: User

Technology: struts1 + JSP + msql

Requirement: The ncmgt network monitoring system displays the user's operation logs, and queries the user's detailed operation records based on the operation time. The time is accurate to seconds.

The general effect is as follows ,!

You can clearly see that the red line is based on the time query, the time is accurate to the second, should not be manually input by the user, or it will greatly reduce the performance of the user experience, this is the time used the widget is something like this little clock, but it is just a picture. We need to know what is hidden behind it. Let's show you the effect first. When we click the little clock, pop-up

Such a calendar image, you can see that the bottom line is added with the time, the second, the default is not Oh,

The following describes how to achieve this effect,

Step 1:

Introduce JS files

The header of the JSP page

<Script
Language = "JavaScript"
Src = "http: // localhost: 8080/ncmgt // JS/calendar. js"> </SCRIPT>

Step 2:

Prepare a small image,

<! -- The text box is used to receive the selected time and pass the oplog object class attributes in the form -->


<Input
Type = "text"
Name = "oplogsearch. datebegin"
Size = "16"
Value = ""
Readonly = "readonly"
Class = "textarea1">

<
Href = "javascript: buildcal (oploglistform. elements ['oplogsearch. datebegin'], true)"> Id = "img1"
Src = "http: // localhost: 8080/ncmgt // img/public/clock.gif"
Alt = "select date"
Width = "20"
Height = "20"
Border = "0"> </a> when the user selects the time, the following function puts the time in the text box and submits the form function closewin (){

// Get the Signature Name and time parent.doc ument. forms ["0"]. elements ["oplogsearch. opname "]. value = document. forms ["0"]. elements ["oplogsearch. opname "pai.value?parent.doc ument. forms ["0"]. elements ["oplogsearch. datebegin "]. value = document. forms ["0"]. elements ["oplogsearch. datebegin "pai.value=parent.doc ument. forms ["0"]. elements ["oplogsearch. dateend "]. value = document. forms ["0"]. elements ["oplogsearch. dateend "pai.value=parent.doc ument. forms ["0" 2.16.submit(partition partition parent.doc ument. getelementbyid ('divwindow '). style. display = "NONE ";
Return false;} is not a result of submitting a form. It is very important to have a process. If the user chooses the time from 5.3 to 5.1. That is, what we often say is greater than and smaller than small. This is not logical. It is like a number greater than 3 and less than 1. Where is this? In order to avoid such a value from being uploaded to the background action, we should process function comparepair (){

VaR begin, end; begin = document. forms ["0"]. elements ["oplogsearch. datebegin "]. value; end = document. forms ["0"]. elements ["oplogsearch. dateend "]. value; If (begin> end & End! =
"") {Alert ("the time you selected is incorrect! ');
Return false;
} Return true;} it will be processed in the background. Another point is that the MySQL database I use and the processing time in MySQL cannot use to_date () that is the date function in Oracle. We can use date. format ();
For example:
Select count (*) from nc_op_log where 1 = 1 and date <= date_format ('2017-05-03 17:28:39 ', 'yyyy-MM-DD hh24: MI: ss ') and date> = date_format ('2017-05-01 17:28:43 ', 'yyyy-MM-DD hh24: MI: ss ')

However, if your field is of the date type and does not need any function, you can directly query the result by string processing. For example: Select count (*) from nc_op_log where 1 = 1 and date> = '2017-05-01 17:28:43 'and date <= '2017-05-03
17:28:39'

 

Xiaofeng message:

Thank you for taking the time to read my blog, and your eyes must be sour. Let's take a look at the beauty, and the cute little girl. I believe it will make you feel good. Xiaofeng blog welcomes you.

Http://my.csdn.net/se_xiaofeng
Welcome to my blog!

Which one is more cute?

Related Article

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.