I have two date like:
String date_1="yyyyMMddHHmmss";
String date_2="yyyyMMddHHmmss";
I want to print the difference like:
2d 3h 45m
How can I do that? Thanks!
I have two date like:
String date_1="yyyyMMddHHmmss";
String date_2="yyyyMMddHHmmss";
I want to print the difference like:
2d 3h 45m
How can I do that? Thanks!
I use this: send start and end date in millisecond
You can generalize this into a function that lets you choose the output format
Now is a simple function call like this, difference in hours, minutes and seconds:
You can calculate the difference in time in miliseconds using this method and get the outputs in seconds, minutes, hours, days, months and years.
You can download class from here: DateTimeDifference GitHub Link
it returns how many days between given two dates, where
DateTime
is from joda libraryShort & Sweet:
Usage:
Output:
I arranged a little. This works great.