Issue
I want to get the two calender time difference
my calender is
val calendar1 = Calendar.getInstance()
calendar1[Calendar.HOUR+1] = hour.toString().toInt()
calendar1[Calendar.MINUTE] = minute.toString().toInt()
this is giving in 12 hours format Wed Nov 17 06:30:31 GMT+05:30 2021
current calender is:-
val calendar = Calendar.getInstance()
calendar[Calendar.HOUR]=calendar.get(Calendar.HOUR)
calendar[Calendar.MINUTE]=calendar.get(Calendar.MINUTE)
this is giving in 24 hours format Wed Nov 17 18:01:32 GMT+05:30 2021
how to get this calender in 12 hours format
thats why im having difficult in finding two calender difference
can anyone help?
Solution
In first calender you are using
calendar1[Calendar.HOUR+1]
-> which will be equivalent to calendar1[Calendar.HOUR_OF_DAY]
Here are the constants from Calendar class
public static final int HOUR = 10;
public static final int HOUR_OF_DAY = 11;
use calendar1[Calendar.HOUR]
for 24 hour format .
Better way is to get millis from both calenders and find difference between 2 millis .
To get millis use calendar.time.time
for getting difference between millis see this answer
Answered By - Manohar
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.