Date Processing of Java string type

Source: Internet
Author: User
Import java. Text .*;
Import java. util .*;

Public class test ...{
Public static void main (string [] ARGs) throws exception ...{
String str1 = new string ("1986-02-4 ");
String str2 = new string ("1986-2-8 ");

Java. Text. simpledateformat = new simpledateformat ("yyyy-mm-dd ");
Date d1 = simpledateformat. parse (str1 );
Date D2 = simpledateformat. parse (str2 );

Long DMM = d2.gettime ()-d1.gettime ();
Int d = (INT) DMM/1000/60/60/24;



System. Out. println (d );

String str3 = "20070101000000 ";
Simpledateformat F2 = new simpledateformat ("yyyymmddhhmmss ");

Date D3 = f2.parse (str3 );

System. Out. println (D3 );



}

}

 

The string type is changed to Java. SQL. Date.

If the character transfer meets the yyyy-mm-dd type

Java. SQL. Date time = java. SQL. Date. valueof ");

Pass the character to Java. SQL. date type. java. SQL. date is a subclass of Java. util. Date.

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.