public class DateFormatTest {
private final DateFormat format =
new SimpleDateFormat("yyyyMMdd");
public Date convert(String source)
throws ParseException{
Date d = format.parse(source);
return d;
}
}
final DateFormatTest t =new DateFormatTest();
Callable<Date> task =new Callable<Date>(){
public Date call()throws Exception {
return t.convert("20100811");
}
};
//让我们尝试2个线程的情况
ExecutorService exec = Executors.newFixedThreadPool(2);
List<Future<Date>> results =
new ArrayList<Future<Date>>();
//实现5次日期转换
for(int i =0; i <5; i++){
results.add(exec.submit(task));
}
exec.shutdown();
//查看结果
for(Future<Date> result : results){
System.out.println(result.get());
}
public Date convert(String source)
throws ParseException{
synchronized(format) {
Date d = format.parse(source);
return d;
}
}
public class DateFormatTest {
private static final ThreadLocal<DateFormat> df
= new ThreadLocal<DateFormat>(){
@Override
protected DateFormat initialValue() {
return new SimpleDateFormat("yyyyMMdd");
}
};
public Date convert(String source)
throws ParseException{
Date d = df.get().parse(source);
return d;
}
}
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import java.util.Date;
public class DateFormatTest {
private final DateTimeFormatter fmt =
DateTimeFormat.forPattern("yyyyMMdd");
public Date convert(String source){
DateTime d = fmt.parseDateTime(source);
returnd.toDate();
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有