title: CountDown Timer - How to Show Year, Months, Weeks as well
body: <p>In my program i have to show CountDown Timer and for that i wrote some code, which allow me to get Days, Hours, Minutes and Seconds, but not getting any idea how to calculate Year, Months and weeks as well.</p>
  
  <p>Still i am getting this:</p>
  
  <pre><code>days:384 hours:6 minutes:27 seconds:25
  </code></pre>
  
  <p>but i need this:</p>
  
  <pre><code>year:1 months:2 weeks:5 days:125 hours:6 minutes:27 seconds:25
  </code></pre>
  
  <p>Check my below code :</p>
  
  <pre><code>      public class MainActivity extends Activity {
      String time1="31-08-2015 12:01:00";
      TextView tv;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.fragment_main);
  
          tv=(TextView)findViewById(R.id.textView1);
  
          final Handler handler = new Handler();
          handler.postDelayed(new Runnable() {
  
              @Override
              public void run() {
                  Calendar start = Calendar.getInstance();  
                  String time = "dd-MM-yyyy hh:mm:ss"; // 12:00
  
                  String dateStart =(String) DateFormat.format(time, start);                          
                  String dateStop = time1;
  
  
                   SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");  
                  // Custom date format
                  java.util.Date d1=null;
                  java.util.Date d2=null;
                    try {
                          d1 = format.parse(dateStart);
                          d2 = format.parse(dateStop);
                      } catch (java.text.ParseException e) {
                          // TODO Auto-generated catch block
                          e.printStackTrace();
                      }
  
                  long diff = d2.getTime() - d1.getTime();             
  
                  long diffdays    =(diff/ (1000*60*60*24));
                  long diffHours = ((diff - (1000*60*60*24*diffdays)) / (1000*60*60));                             
                  long diffMinutes = (diff - (1000*60*60*24*diffdays) - (1000*60*60*diffHours)) / (1000*60);  
                  long diffSeconds =(diff - (1000*60*60*24*diffdays) - (1000*60*60*diffHours) -(1000*60*diffMinutes))/ (1000);                
  
                  String out= "days:"+diffdays+  "hours:"+diffHours+  "Minutes:"+diffMinutes+  "seconds:"+diffSeconds;
                  tv.setText(out);
  
                  handler.postDelayed(this, 1000);
              }
          }, 1000); 
      }
  
  }
  </code></pre>