Java Time Different diffTime(String sTime, String fTime, String Dateformat1)

Here you can find the source of diffTime(String sTime, String fTime, String Dateformat1)

Description

diff Time

License

Open Source License

Declaration


public static int diffTime(String sTime, String fTime, String Dateformat1) throws

Exception 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.text.SimpleDateFormat;
import java.util.Calendar;

public class Main {

    public static int diffTime(String sTime, String fTime) throws Exception {

        SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        java.util.Date stime = myFormatter.parse(sTime);

        java.util.Date ftime = myFormatter.parse(fTime);

        int second = (int) ((ftime.getTime() - stime.getTime()) / 1000);

        return second;

    }//  ww  w .  j ava  2s . co  m

    public static int diffTime(String sTime, String fTime, String Dateformat1) throws

    Exception {

        SimpleDateFormat myFormatter = new SimpleDateFormat(Dateformat1);

        java.util.Date stime = myFormatter.parse(sTime);

        java.util.Date ftime = myFormatter.parse(fTime);

        int second = (int) ((ftime.getTime() - stime.getTime()) / 1000);

        return second;

    }

    public static String getTime() {

        Calendar calendar = Calendar.getInstance();

        String strHour = "" + calendar.get(Calendar.HOUR_OF_DAY);

        if (strHour.length() == 1)

            strHour = "0" + strHour;

        String strMinute = "" + calendar.get(Calendar.MINUTE);

        if (strMinute.length() == 1)

            strMinute = "0" + strMinute;

        String strSecond = "" + calendar.get(Calendar.SECOND);

        if (strSecond.length() == 1)

            strSecond = "0" + strSecond;

        String curTime = strHour + strMinute + strSecond;

        return curTime;

    }
}

Related

  1. calculateExecutionTimeDiff(String startDate, String endDate)
  2. createDate(String strDate, int[] timeDiff, boolean plusDiff)
  3. getDiffDateTime(int diff)
  4. getDifferent(final Date timeFrom, final Date timeTo)
  5. getDiffTime(Date beforeTime, Date afterTime)
  6. getDiffTime(long startTime)