Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculate Time Difference in Android

Tags:

android

I am new in Android.I can't find any way to calculate the time difference.So please help me. I designed a simple application. In this program I took 3 EditTexts and in these EditText I want to input the login time and logout time then store these values in the Database, And in the 3rd EditText I want to display the difference between these two time.

like image 367
Tripaty Sahu Avatar asked Feb 26 '11 15:02

Tripaty Sahu


2 Answers

You can use standard Java api calls:

System.nanoTime()
System.currentTimeMillis()

Also, check out these two links for calculating time difference.

like image 161
dSebastien Avatar answered Sep 25 '22 14:09

dSebastien


An easier approach -

Date interestingDate = new Date();

different in milliseconds between the actual current date and interestingDate by doing:

(new Date()).getTime() - interestingDate.getTime();

Check the referenced answer in this link.

like image 24
Darpan Avatar answered Sep 22 '22 14:09

Darpan