JavaScript uses regular expressions to remove-

Source: Internet
Author: User

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.

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.