1, need to convert the string (20150210125942), after conversion to achieve the purpose: 2015-02-10 12:59:42
Public Static voidMain (string[] args) {String strdatetime= "20150210125942"; System.out.println (convjsondatetostring (Strdatetime, "Yyyymmddhhmmss","Yyyy-mm-dd HH:mm:ss")); System.out.println (Priceint);} Public Staticstring convjsondatetostring (String jsondate,string jsontemplate,string stringtemplate) {string ResultS Tring=NULL; Try{Calendar Cldcalendar=Convtocalender (Jsondate, jsontemplate); Resultstring=convtostring (Cldcalendar, stringtemplate); } Catch(Exception e) {//TODO auto-generated Catch blockE.printstacktrace (); } returnresultstring;}
Output results: 20150210125942
Error reason: stringteplate= "Yyyy-mm-dd HH:mm:ss"
Change to: stringteplate= "Yyyy-mm-dd hh:mm:ss"
Just change the capitalization.
Java cannot cut date string to Yyyy-mm-dd Hh:mm:ss