-4

I want to get my android device date and check with current date and compare number of days left. Tab or device doesn't have SIM also. Thanks!

Nabin
  • 11,216
  • 8
  • 63
  • 98
Shailesh
  • 79
  • 8
  • 1
    What do you exactly want? Do you want to calculate the difference between current date and the day when next SIM will be inserted? Or with the day when it will be turned on? – Nabin Sep 01 '14 at 14:16
  • see this solution http://stackoverflow.com/a/17175444 – QArea Sep 01 '14 at 14:52

2 Answers2

5

Android API for managing times android.text.format.Time

For getting current time:

Time time = new Time();
time.setToNow();

To calculate differences between two time, you can try this code

Time time1;
Time time2;
long diff = time1.toMillis(false) - time2.toMillis(false);
// Now 'diff' contains difference between those two time in milliseconds

Update #1

This class was deprecated in API level 22.

frogatto
  • 28,539
  • 11
  • 83
  • 129
4

You can use this code to get the device date.

SimpleDateFormat s = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss", Locale.getDefault());
String dateFormat = s.format(new Date(System.currentTimeMillis()));
halfer
  • 19,824
  • 17
  • 99
  • 186
Harry Mad
  • 488
  • 5
  • 17
  • 134
    Please see http://stackoverflow.com/editing-help for help on formatting your posts. When others edit your posts for you to improve the formatting in a non-destructive way, the least you can do is to appreciate their help. If you don't like the idea of anyone else editing your posts for any reason, then this site may not be for you. See http://stackoverflow.com/help/editing – BoltClock Sep 03 '14 at 05:00
  • 22
    Thanks @BoltClock for your valuable suggestions. I will go these links and improve my knowledge. – Harry Mad Sep 04 '14 at 04:46
  • 5
    Calling `new Date()` is the same as `new Date(System.currentTimeMillis())` – Pointy Sep 05 '14 at 14:21