I need in my application to convert minutes to 24 hour formart, for example my app has a method that
return a time in minutes 260, how can I convert this time to 24 format?
thanks so much ,,
— After upadting ———————————————————————-
//Inside OnCreate Method
//For Time Part#1
CaseDurationH.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
int i = CaseDurationH.getSelectedItemPosition();
strH = parent.getSelectedItem().toString();
try {
intH = Integer.parseInt(strH);
intHInMin=intH*60; // inH and intHInMin are a integer
} catch (NumberFormatException nfe) {
}
if(i==2){
CaseDurationM.setEnabled(false);
}
if(strH.equals("hr0"))
{
CaseDurationM.setEnabled(true);
}
if(strH.equals("hr1"))
{
CaseDurationM.setEnabled(true);
}
if(strH.equals("hr2"))
{
CaseDurationM.setEnabled(false);
}
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
} });
//For Time Part#2
CaseDurationM.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
int i = CaseDurationM.getSelectedItemPosition();
strM = parent.getSelectedItem().toString();
try {
intM = Integer.parseInt(strM);
} catch (NumberFormatException nfe) {
}
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
} });
String CaseTime= calc();
case1.setTime(CaseTime); //case1 is an Onbject
//Out OnCreate Method
private String calc() {
int CTimeTotalInMin= intHInMin + intM;
Calendar calendar = new GregorianCalendar();
int CurrentHour = calendar.get(Calendar.HOUR);
int CurrentMinute = calendar.get(Calendar.MINUTE);
int CurrentTime= (CurrentHour * 60)+ CurrentMinute;
int TotalTimeInMin= CurrentTime-CTimeTotalInMin;
int hours = TotalTimeInMin / 60;
int minutes = TotalTimeInMin % 60;
if(hours>23)
hours = hours % 24;
String g = ""+hours+":"+minutes;
return g;}
my problem is: How can I get the (current Time – the time selected by the user from the Spinner
(I show the user two lists for hours ( 0h or 1h or 2h) and Minutes ( from 0-59) as shown below,
for instant, if the user select (1 hour ) and the current time is (2:15 PM) the answer should be= 13:15 PM), I tried this code but it couldn’t differ from PM and AM ?
any Suggestion ? thanks alot…
<!-- @ string.xml these imtes for CDurationH= hours -->
<string name="hr0">0</string>
<string name="hr1">1</string>
<string name="hr2">2</string>
<!-- @ string.xml these imtes for CDurationM= minutes -->
<string name="min0">0</string>
<string name="min5">5</string>
<string name="min10">10</string>
<string name="min15">15</string>
<string name="min20">20</string>
<string name="min25">25</string>
<string name="min30">30</string>
<string name="min35">35</string>
<string name="min40">40</string>
<string name="min45">45</string>
<string name="min50">50</string>
<string name="min55">55</string>
<string name="min59">59</string>
Calculate hour and minute values via division and modulus operators.
Check for possible hour values greater than 23 indicating exceed of a daytime.
Format your values to represent as 24 hour format: