首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

SimpleDateFormat有关问题及解决方案

2012-09-10 
SimpleDateFormat问题及解决方案1.每次使用SimpleDateFormat前都new一个新对象,这个做法的缺点是效率较低;

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的库比较好用,木有用过)

?

热点排行