I am trying to add a number of minutes to the current Time in android.
I want to use the Simpledateformat as ("EEE, d MMM yyyy HH:mm:ss Z")
Firstly I want to explain what my concept is.
- There is a Recyclerview List where on each Row, A user selects a time. suppose I select 50 Minutes. this 50 minutes is added to the current time and stored in the database.
I have used the code...
String t = time.getText().toString();
int ti = Integer.parseInt(t);
@SuppressLint("SimpleDateFormat") SimpleDateFormat sdf = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
Calendar now = Calendar.getInstance();
String a = now.get(Calendar.HOUR_OF_DAY) + ":" + now.get(Calendar.MINUTE) + ":" + now.get(Calendar.SECOND);
now.add(Calendar.MINUTE,ti);
a = now.get(Calendar.HOUR_OF_DAY) + ":" + now.get(Calendar.MINUTE) + ":" + now.get(Calendar.SECOND);
adminList = mFirestore.collection("AdminList");
Map<String,Object> k = new HashMap<>();
k.put("order",order);
k.put("status","Pending");
k.put("hotel_name",hotel);
k.put("user_id",userid);
k.put("time",a);
adminList.document(order).update(k);
- The User Gets This Time From the Database, and subtract it from the current Time per second so that the list is shown with a Countdown Timer.
code for this is.
void updateTimeRemaining(String text) {
if (o.getOrder().equalsIgnoreCase("order1")) {
try {
TimeZone.setDefault(TimeZone.getDefault());
String stop = ol.getTime();
@SuppressLint("SimpleDateFormat") SimpleDateFormat format = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
Calendar end_date = Calendar.getInstance();
end_date.setTime(format.parse(stop));
final Calendar today = Calendar.getInstance();
timeDiff = end_date.getTimeInMillis() - today.getTimeInMillis();
if (timeDiff > 0) {
long seconds = timeDiff / 1000 % 60;
long minutes = timeDiff / (60 * 1000) % 60;
long hours = timeDiff / (60 * 60 * 1000) % 24;
//long days = (int) timeDiff / (24 * 60 * 60 * 1000);
//long days = TimeUnit.MILLISECONDS.toDays(timeDiff);
String left = "";
//if (days > 0)
// left += days + " " + /*context.getString(R.string.txt_day) +*/ ":";
if (hours > 0)
left += hours + " " +/* context.getString(R.string.txt_hour) + */":";
if (minutes > 0)
left += minutes + " " +/* context.getString(R.string.txt_minute) + */":";
left += seconds + " " /*+ context.getString(R.string.txt_second)*/;
String finalLeft = left;
text = finalLeft;
time.setText("00:" + finalLeft);
} else {
time.setText("Finished");
}
// }
} catch (Exception ex) {
ex.printStackTrace();
}
// }
}
So My Final Problem is,
How can I add 50 minutes to the Current Time and with the format "EEE, d MMM yyyy HH:mm:ss Z"