@Test 公共 ボイドTEST01(){ カレンダーカレンダー = Calendar.getInstance(); // calendar.set( 2019,06,04,16,42,50 )。 長い DATE1 = calendar.getTimeInMillis()。 長い日付2 = にSystem.currentTimeMillis(); 日turnDate1 = 新しい日付(DATE1)。 日turnDate2 = 新しい日付(日付2)。 SimpleDateFormat FM = 新しいてSimpleDateFormat( "YYYY-MM-DD HH:MM:SS" )。 System.out.println(fm.format(turnDate1))。 System.out.println(fm.format(turnDate2))。 }
二回は同じです。
2.性能比較
/ ** *何千回も各ループのタイムスタンプを取得 * / @Test 公共 無効TEST03(){ カレンダーカレンダー = ; Calendar.getInstance() ロングのstartTime = にSystem.currentTimeMillis(); のため(ロング I = 0; I <100000 ; Iは++ ){ ロング日付1 = ()calendar.getTimeInMillis } のSystem.out.println( - :+(のSystem.currentTimeMillis() "に費やさカレンダー時間" ;)のstartTime) ロング startTime2 = ;のSystem.currentTimeMillis() のために(長い I = 0;私は100000 <; Iは++ ){ 長い DATE2 = にSystem.currentTimeMillis(); } のSystem.out.println( "使用済カレンダー時間:" +(のSystem.currentTimeMillis() - startTime2)); }
見つかったこのマシンのテストが不安定です。使用されているソースコードのSystem.currentTimeMillisを表示するnativae方法は、これが速く取る時間だと思います。私を修正してください