Java calculate the time difference between the two dates (milliseconds)

Java calculate the time difference between two dates

package com.test1;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class GetTimeDistance {
    
    public static void main(String[] args) throws ParseException {
        Date date1 = new Date();
        Date date2 = new Date();
        
        SimpleDateFormat sdf = new SimpleDateFormat("YYYY/MM/dd HH:mm:ss.SSS");  
        
    
        String d_1w_ifc_start = "2020/01/11 17:21:36.645";
        String d_1w_ifc_end = "2020/01/11 17:22:51.347";

        String d_1w_mysql_start = "2020/01/11 17:22:51.347";
        String d_1w_mysql_end = "2020/01/11 17:22:51.716";
        System.out.println(getTime(d_1w_ifc_start,d_1w_ifc_end)+"  "+getTime(d_1w_mysql_start,d_1w_mysql_end));
        
        
    }
    
    // Get the time difference between the number of minutes two 
    public  static  Long the getTime (oldtime String, String NewTime) throws a ParseException {
 
        DF the SimpleDateFormat = new new the SimpleDateFormat ( "YYYY / the MM / dd HH: mm: ss.SSS" );
         Long Ntime = df.parse (NewTime) .getTime ();
         // get the object from the time 
        Long Otime = df.parse (oldtime) .getTime ();
         Long the diff = (NTime- Otime);
         return the diff;
    }

}

 

74702    369

Guess you like

Origin www.cnblogs.com/herd/p/12180548.html