1. Description
This often happens, the date format of the page is: YYYY-MM-DD, And the date format in the database is: YYYYMMDD, need to convert between the two, can be uploaded to the Java background query data.
Generally, there are two conversion methods. The first is to extract the date string and then splice it. The second is to remove "-" using a regular expression.
In comparison, the second method is quick and error-prone.
2. Source Code
Copy codeThe Code is as follows:
<% @ Page language = "java" import = "java. util. *" pageEncoding = "UTF-8" %>
<! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN">
<Html>
<Head>
<Title> remove "-" from the date using JavaScript </title>
<Meta http-equiv = "pragma" content = "no-cache">
<Meta http-equiv = "cache-control" content = "no-cache">
<Meta http-equiv = "expires" content = "0">
<Meta http-equiv = "keywords" content = "keyword1, keyword2, keyword3">
<Meta http-equiv = "description" content = "This is my page">
<Script type = "text/javascript">
Function dateFormat ()
{
Var date = "2014-06-08 ";
Alert ("date before replacement:" + date );
// Replace "-"
Var dateStr = date. replace (/\-/g ,"");
Alert ("date after replacement:" + dateStr );
}
</Script>
</Head>
<Body>
<Input type = "button" value = "date formatting" onclick = "dateFormat ()"/>
</Body>
</Html>
3. Implementation result
(1) During Initialization
(2) Click OK.