Today when doing the WebService interface service, the XML file is passed into a node for the person's birth date, the corresponding entity class field type is the date type, the value obtained is string type, the code is as follows:
Gets a value of "19570323" String datestring = Emp.gethealthcareprincipalperson (). Getbirthtime (). GetValue
(). toString ();
1. Define conversion format SimpleDateFormat formatter = new SimpleDateFormat ("Yyyy-mm-dd");
SimpleDateFormat formatter2 = new SimpleDateFormat ("YyyyMMdd"); 2, call Formatter2.parse (), convert "19570323" to date type output as: Sat Mar 00:00:00 gmt+08:00 1957 date = Formatter2.parse (
datestring);
3. Convert Date type (Sat 00:00:00 gmt+08:00 1957) to String type//Note now formatter is used for conversion and output is of type string: "1957-03-23"
String dstring = Formatter.format (date);
4. Converting a string to date requires notice that the java.sql.Date.valueOf () function can only accept Date data = Java.sql.Date.valueOf (dstring) with a parameter type of YYYY-MM-DD type; 5. Assigns the date-type birthdate to JavaBean personaudit.setbirthdate (Emp.gethealthcareprincipalp Erson ()!= null && Emp.gethealthcareprincipalperson (). Getbirthtime ()!= null)? data:null);