- So before this I already get the time difference between two times.
- Now, I want to display point that will be charged for specific time duration like this: in my code, time duration named as diffResult, if diffResult less than 30 minutes, point will be charged is multiply by 1 diffResult =2, so 2*1 ,point will be charged is 2.
-
I wanted to use if else statement, but I got some errors. Here is my code
pointChargeBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm a"); Date date1 = null; try { date1 = simpleDateFormat.parse(timeResult.getText().toString()); } catch (ParseException e) { e.printStackTrace(); } Date date2 = null; try { date2 = simpleDateFormat.parse(timeResult2.getText().toString()); } catch (ParseException e) { e.printStackTrace(); } String diffResult= DateUtils.getRelativeTimeSpanString(date1.getTime(), date2.getTime(), DateUtils.MINUTE_IN_MILLIS).toString(); if(diffResult < 30){ int point = diffResult * 2; pointChargeBtn.setText(point); } } });
mardi 1 mai 2018
if else statement for DateUtils
Inscription à :
Publier les commentaires (Atom)
Aucun commentaire:
Enregistrer un commentaire