SimpleDateFormat问题及解决方案
1.每次使用SimpleDateFormat前都new一个新对象,这个做法的缺点是效率较低;
? ? 2.使用apache的commons-lang包下的FastDateFormat,代码如下:
FastDateFormat fdfWithoutTime=FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss",TimeZone.getDefault(), Locale.getDefault());
String time=fdfWithoutTime.format(new Date());
(很不幸的是FastDateFormat只能进行format不能进行parse,据说有个叫JodaTime的库比较好用,木有用过)
?