Package com.iamzken.utils;
Import java.text.ParseException;
Import Java.text.SimpleDateFormat;
Import java.util.Date;
public class Dateformattest {public
static void Main (string[] args) throws ParseException {
// According to the time format in the database to new a corresponding SimpleDateFormat date converter, because the data extracted from the database format is similar to: 2015-10-10 23:20:20.23
// The new SimpleDateFormat format is as follows:
simpledateformat DateFormat = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss. S ");
The date converter is used to convert the date string retrieved in the database to date type, as an example of "2015-10-10 23:20:20.23",
//actually replace it with your own a.getcdate () date
CDate = Dateformat.parse ("2015-10-10 23:20:20.23");
Re-build a date converter, specify the format you want to convert
String result = new SimpleDateFormat ("yyyy mm-month DD Day hh time of the second s)." Format ( CDate);
SYSTEM.OUT.PRINTLN (result);
}
The summary is also two steps: 1. String is converted to date 2 by the SimpleDateFormat format of the string itself, and the date is converted to the target string through its own specified SimpleDateFormat format
When you can not forget the foundation Ah, what to do, basic skills must be solid ...