String converted to Data date type

Source: Internet
Author: User

For example: (a) Java language code

Converts a time input string tm= "1999-12-22" (time) to date (Java.sql.Date not java.util.Date)
And then in the DateTime-type Time field saved to SQL!
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

SimpleDateFormat SDF = new SimpleDateFormat ("Yyyy-mm-dd");
String aa= "1999-12-22";
Java.util.Date timedate = null;
try {
Timedate = Sdf.parse (AA);
catch (ParseException e) {
TODO automatically generate catch blocks
E.printstacktrace ();
}//util type
Java.sql.Date dateTime = new Java.sql.Date (Timedate.gettime ());//sql type

For example: (i) Oracle

can be converted using Oracle's to_date function,
or java.sql.Date (int   year,   int   month,   int   day)   , it is automatically corresponding to the date type of Oracle; For example:
String   LSTR   =   "02-06-2003";
int   Lday   =   Integer.parseint (lstr.substring (0,2));
int   Lmon   =   Integer.parseint (lstr.substring (3,5));
int   Lyear   =   Integer.parseint (lstr.substring (6));

Date   ldate   =   new   Date (lyear,   Lmon,   lday);

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.