I need to get the time when the user is touching a button. like, when the user is touching button1, I need it to save the exact hour, minute and date of touching this button. how can I do it?
Asked
Active
Viewed 1.2k times
2 Answers
6
You can try the following code:
Calendar calendar = Calendar.getInstance(Locale.getDefault());
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);
int second = calendar.get(Calendar.SECOND);
int date = calendar.get(Calendar.DAY_OF_MONTH);
int month = calendar.get(Calendar.MONTH);
int year = calendar.get(Calendar.YEAR);

Kanchan Chowdhury
- 433
- 1
- 5
- 15
4
System.currentTimeMillis()
You can use this function to escape creation of date object.
You can persist it as long and you always can create Date object of it.

chilltouch
- 281
- 2
- 10