Difference calendar.getTimeInMillis () and System.currentTimeMillis () of

   @Test
    public void test01(){
        Calendar calendar=Calendar.getInstance();
       // calendar.set(2019,06,04,16,42,50);
        long date1=calendar.getTimeInMillis();
        long date2=System.currentTimeMillis();
        Date turnDate1=new Date(date1);
        Date turnDate2=new Date(date2);
        SimpleDateFormat fm=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println(fm.format(turnDate1));
        System.out.println(fm.format(turnDate2));

    }

 

Two times are the same.

 2. Performance Comparison

   / ** 
     * Get timestamp of thousands of times each loop 
     * / 
    @Test 
    public  void TEST03 () { 
        Calendar Calendar = Calendar.getInstance ();
         Long the startTime = System.currentTimeMillis ();
         for ( Long I = 0; I <100000 ; I ++ ) {
             Long date1 = calendar.getTimeInMillis (); 
        } 
        System.out.println ( "calender time spent:" + (System.currentTimeMillis () - the startTime)); 

        Long startTime2 = System.currentTimeMillis ();
         for ( Long I = 0; I <100000; I ++ ) {
            Long DATE2 = System.currentTimeMillis (); 
        } 
        System.out.println ( "calender time spent:" + (System.currentTimeMillis () - startTime2)); 
    }

This machine tests found is unstable. nativae way to view the source code System.currentTimeMillis used guess this is the time to take faster. Please correct me

 

Guess you like

Origin www.cnblogs.com/blogxiao/p/10978270.html