One: Convert time Date type to string type
1 /** 2 * Convert date type to String type3 * @paramDate4 * @return 5 */ 6 Public StaticString datetostring (date date) {7DateFormat format =NewSimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"); 8 returnFormat.format (date); 9}
Two: Convert string type to date type
1 /** 2 3 * Convert String type to date type4 * @paramDate5 * @return 6 */ 7 Public StaticDate stringtodate (String date) {8DateFormat format =NewSimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"); 9Date d =NULL; Ten Try { OneD =format.parse (date); A}Catch(java.text.ParseException e) { - E.printstacktrace (); - } the returnD; -}
Three: Simultaneous judgment of "'" and null two cases
1 /** 2 * Determine if the variable is empty3 * @params4 * @return 5 */ 6 Public Static BooleanIsEmpty (String s) {7 if(NULL= = S | | ". Equals (s) | |" ". Equals (S.trim ()) | | "NULL". Equalsignorecase (s)) { 8 return true; 9}Else{ Ten return false; One } A}
Four: Remove the space before and after the string
1 /** 2 * Remove spaces before and after a string3 * @params4 * @return 5 */ 6 Public Staticstring Trim (string s) {7 if(NULL==s) { 8 return""; 9}Else{ Ten returnS.trim (); One } A}
V: Used to remove the list of empty values and the same items.
1 /** 2 * Used to remove the list of empty values and the same items. 3 * @paramList4 * @return 5 */ 6 PublicList<string> Removesameitem (list<string>list) { 7List<string> diflist =NewArraylist<string>(); 8 for(String t:list) {9 if(t! =NULL&&!diflist.contains (t)) { Ten Diflist.add (t); One } A } - returndiflist; -}
Six: The current days plus one day
1 /** 2 * Number of days plus one3 * @paramDateTime4 * @return 5 * @throwsException6 */ 7 Public StaticString Datefamte (String dateTime)throwsexception{8SimpleDateFormat format =NewSimpleDateFormat ("Yyyy-mm-dd"); 9Date Date =Format.parse (dateTime); TenCalendar calendar = Calendar.getinstance ();//Calendar Object OneCalendar.settime (date);//set the current date ACalendar.add (Calendar.day_of_month, 1);//days plus One - returnFormat.format (Calendar.gettime ()); -}
Seven: Convert a JSON string to a Java object
1 /** 2 * Get an array of Java objects from a JSON array, such as:3 * [{"id": Idvalue, "name": Namevalue}, {"id": Idvalue, "name": Namevalue}, ...] 4 * @paramObject5 * @paramClazz6 * @return 7 */ 8 Public Staticobject[] Getdtoarray (String jsonstring, Class clazz) {9Jsonarray array =Jsonarray.fromobject (jsonstring); Tenobject[] obj =Newobject[array.size ()]; One for(inti = 0; I < array.size (); i++){ AJsonobject Jsonobject =Array.getjsonobject (i); -Obj[i] =Jsonobject.tobean (Jsonobject, clazz); - } the returnobj; -}
Do the method in the tool class commonly used in the Java EE Project!