zsh_root
2024-01-02 7b595546af704983dbafcd0d385c8768ddacefc2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package Method;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
/**¸ÃÀàÓÃÓÚʱ¼ä¼ÆËã*/
public class TiemDell {
    
    private static final String aa = "yyyy-MM-dd HH:mm:ss";
     /**»ñÈ¡Á½¸öʱ¼äÏà²îºÁÃëÊý*/
    public static long getTime(String oldTime,String newTime)  { 
      SimpleDateFormat df = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss.SSS");
      long NTime = 0;
      long OTime = 0;
        try {
            NTime = df.parse(newTime).getTime();
            OTime = df.parse(oldTime).getTime();
        } catch (ParseException e) {
            // TODO ×Ô¶¯Éú³ÉµÄ catch ¿é
            e.printStackTrace();
        }
      
      long diff=(NTime-OTime);
      return diff;
  }
    
    public static int getTimeDelta(Date date1,Date date2){
        long timeDelta=(date1.getTime()-date2.getTime())/1000;//µ¥Î»ÊÇÃë
        int secondsDelta=timeDelta>0?(int)timeDelta:(int)Math.abs(timeDelta);
        return secondsDelta;
    }
    
    /**»ñÈ¡Á½¸öʱ¼äÏà²îÃëÊý*/
    public static int getTimeDelta(String stoptime,String Startime){
        Date date1=parseDateByPattern(stoptime, aa);
        Date date2=parseDateByPattern(Startime, aa);
        return getTimeDelta(date1, date2);
    }
   
    
    public static Date parseDateByPattern(String dateStr,String dateFormat){
        SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
        try {
            return sdf.parse(dateStr);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }
 
}