Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.util.Log;

import java.util.Date;

public class Main {
    public static String getDateDiff(Date date1, Date date2) {
        long diff = date2.getTime() - date1.getTime();
        long diffInSeconds = diff / 1000 % 60;
        long diffInMinutes = diff / (60 * 1000) % 60;
        long diffInHours = diff / (60 * 60 * 1000) % 24;
        long diffInDays = diff / (24 * 60 * 60 * 1000);
        StringBuilder returnString = new StringBuilder();
        if (diffInDays >= 1) {
            returnString.append(diffInDays + " days ");
        }
        if (diffInHours >= 1) {
            returnString.append(diffInHours + " hours ");
        }
        if (diffInMinutes >= 1) {
            returnString.append(diffInMinutes + " minutes ");
        }
        Log.d("praveen panduru", "timediff is " + returnString.toString());
        return returnString.toString();
    }
}