Last active
August 29, 2015 14:11
-
-
Save omegasoft7/a51d7aabac183dc65d9f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class DateDiff { | |
public long seconds; | |
public long minutes; | |
public long hours; | |
public long days; | |
public DateDiff(long seconds, long minutes, long hours, long days) { | |
this.seconds = seconds; | |
this.days = days; | |
this.minutes = minutes; | |
this.hours = hours; | |
} | |
} | |
@SuppressWarnings("deprecation") | |
public static long pastDaysAgo(Date date) { | |
Date nowDate = new Date(System.currentTimeMillis()); | |
date.setHours(0); | |
date.setMinutes(0); | |
date.setSeconds(0); | |
nowDate.setHours(0); | |
nowDate.setMinutes(0); | |
nowDate.setSeconds(0); | |
return Math.round((nowDate.getTime() - date.getTime()) / 86400000D); | |
} | |
public static DateDiff DiffBetweenDates(Date date1, Date date2) { | |
long diff = date2.getTime() - date1.getTime(); | |
long seconds = diff / 1000; | |
long minutes = seconds / 60; | |
long hours = minutes / 60; | |
long days = hours / 24; | |
return new DateDiff(seconds, minutes, hours, days); | |
} | |
// Make seconds to date format MM:SS | |
public static String MakeTime(int time) { | |
int min = time / 60; | |
int sec = time - (min * 60); | |
return (min < 10 ? "0" + min : min) + ":" + (sec < 10 ? "0" + sec : sec); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment