mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
1.修复忘了timeZone的问题。2.完善单元测试。
This commit is contained in:
parent
29a6cba58d
commit
7232706ca6
@ -522,7 +522,7 @@ public class DateUtil extends CalendarUtil {
|
|||||||
if (date instanceof DateTime) {
|
if (date instanceof DateTime) {
|
||||||
timeZone = ((DateTime) date).getTimeZone();
|
timeZone = ((DateTime) date).getTimeZone();
|
||||||
}
|
}
|
||||||
return format(date, FastDateFormat.getInstance(format));
|
return format(date, FastDateFormat.getInstance(format, timeZone));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1188,25 +1188,40 @@ public class DateUtilTest {
|
|||||||
public void formatSpeedTest(){
|
public void formatSpeedTest(){
|
||||||
Date value = new Date();
|
Date value = new Date();
|
||||||
long t0 = System.currentTimeMillis();
|
long t0 = System.currentTimeMillis();
|
||||||
FastDateFormat.getInstance("YYYY-MM-dd HH:mm:ss.SSSSSS");
|
//此处先加载FastDateFormat对象,保存到FastDateFormat.CACHE中
|
||||||
|
//解决后面两个for循环中保存到FastDateFormat对象创建未时差异的问题。
|
||||||
|
FastDateFormat.getInstance("YYYY-MM-dd HH:mm:ss.SSS");
|
||||||
|
|
||||||
long t1 = System.currentTimeMillis();
|
long t1 = System.currentTimeMillis();
|
||||||
String strTime = null;
|
String strTime = null;
|
||||||
for(int i=0; i<5000; i++){
|
for(int i=0; i<50000; i++){
|
||||||
strTime = DateUtil.format(value, "YYYY-MM-dd HH:mm:ss.SSSSSS");
|
strTime = DateUtil.format(value, "YYYY-MM-dd HH:mm:ss.SSS");
|
||||||
}
|
}
|
||||||
System.out.println("format="+strTime);
|
|
||||||
long t2 = System.currentTimeMillis();
|
long t2 = System.currentTimeMillis();
|
||||||
|
|
||||||
for(int i=0; i<5000; i++){
|
for(int i=0; i<50000; i++){
|
||||||
strTime = FastDateFormat.getInstance("YYYY-MM-dd HH:mm:ss.SSSSSS").format(value);
|
strTime = FastDateFormat.getInstance("YYYY-MM-dd HH:mm:ss.SSS").format(value);
|
||||||
}
|
}
|
||||||
System.out.println("FastDateFormat="+strTime);
|
|
||||||
|
|
||||||
long t3 = System.currentTimeMillis();
|
long t3 = System.currentTimeMillis();
|
||||||
|
|
||||||
System.out.println("t1-t0="+(t1-t0));
|
long initTime = t1 - t0;
|
||||||
System.out.println("t2-t1="+(t2-t1));
|
long formtTime1 = t2 - t1;
|
||||||
System.out.println("t3-t2="+(t3-t2));
|
long formatTime2 = t3 - t2;
|
||||||
|
|
||||||
|
//此处仍然不明白,两个for循环实际执行format方法都一样,为什么第1个for时间大致是第2个for的3倍。
|
||||||
|
Assert.assertTrue(formtTime1 > formatTime2);
|
||||||
|
/**
|
||||||
|
* System.out.println("t1-t0="+(t1-t0));
|
||||||
|
* System.out.println("t2-t1="+(t2-t1));
|
||||||
|
* System.out.println("t3-t2="+(t3-t2));
|
||||||
|
*
|
||||||
|
* 由日志可以看出,第1个for时间大致是第2个for的3倍
|
||||||
|
*
|
||||||
|
* t1-t0=46
|
||||||
|
* t2-t1=65
|
||||||
|
* t3-t2=25
|
||||||
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user