欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

使用DateFormat类格式化Date,dateformatdate,package cn.o

来源: javaer 分享于  点击 48518 次 点评:53

使用DateFormat类格式化Date,dateformatdate,package cn.o


package cn.outofmemory.test;import java.text.DateFormat;import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.Date;public class ConcurrentDateFormatAccess { public Date convertStringToDate(String dateString) throws ParseException {  return SimpleDateFormat.getDateInstance(DateFormat.MEDIUM).parse(dateString); }}
package cn.outofmemory.test;import java.text.DateFormat;import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.Date;public class ConcurrentDateFormatAccess { private DateFormat df = new SimpleDateFormat("yyyy MM dd"); public Date convertStringToDate(String dateString) throws ParseException {  Date result;  synchronized(df) {   result = df.parse(dateString);  }  return result; }}
package cn.outofmemory.test;import java.text.DateFormat;import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.Date;public class ConcurrentDateFormatAccess { private ThreadLocal<DateFormat> df = new ThreadLocal<DateFormat> () {  @Override  protected DateFormat initialValue() {   return new SimpleDateFormat("yyyy MM dd");  } }; public Date convertStringToDate(String dateString) throws ParseException {  return df.get().parse(dateString); }}
相关栏目:

用户点评