Created
April 13, 2018 12:35
-
-
Save erfanegtfi/fd381b94c9df115fb0cd00c8b2fbd4c5 to your computer and use it in GitHub Desktop.
get Time Difference DAY, HOUR, MINUTE, SECOND
This file contains 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 class TimeUtils { | |
public static final long DAY = 86400000; | |
public static final long HOUR = 3600000; | |
public static final long MINUTE = 60000; | |
public static final long SECOND = 1000; | |
public static long getMinuteDifference(long startTime, long endTime) { | |
return (endTime - startTime) / MINUTE; | |
} | |
public static String getTimeDifference(long startTime, long endTime) { | |
long difference = endTime - startTime; | |
int day = 0; | |
int hour = 0; | |
int minute = 0; | |
String and = " \u0648 "; | |
while (difference > DAY) { | |
day++; | |
difference -= DAY; | |
} | |
while (difference > HOUR) { | |
hour++; | |
difference -= HOUR; | |
} | |
while (difference > MINUTE) { | |
minute++; | |
difference -= (long) minute; | |
} | |
if (day < 1 && hour < 1 && minute < 1) { | |
return "\u06a9\u0645\u062a\u0631 \u0627\u0632 \u06cc\u06a9\u200c\u062f\u0642\u06cc\u0642\u0647"; | |
} | |
String result = BuildConfig.VERSION_NAME; | |
if (day > 0) { | |
result = result + LanguageUtils.getPersianNumbers(day + " \u0631\u0648\u0632" + and); | |
} | |
if (hour > 0) { | |
result = result + LanguageUtils.getPersianNumbers(hour + " \u0633\u0627\u0639\u062a" + and); | |
} | |
if (minute > 0) { | |
return result + LanguageUtils.getPersianNumbers(minute + "\u062f\u0642\u06cc\u0642\u0647"); | |
} | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment