title: How to set start time and end time with an interval of 30 minutes in TimePicker Android?
body: <p>I am working on DatePicker and TimePicker in android. I am getting start time and and time from server. I can set max date and min date programmatically using <a href="https://stackoverflow.com/questions/6421874/how-to-get-the-date-set-in-the-datepicker-widget-in-android/7961268#7961268">this link</a></p>
  
  <p>I want to set min time (07:00 ) and max time (10:00) in timepicker and maintain an interval of 30 minutes. I tried using <a href="https://stackoverflow.com/questions/2580216/android-timepicker-minutes-to-15">This Link</a></p>
  
  <p>What i need is to set timepicket with min 07:00 and max time =10:00 and intervals 
  07:00,07:30, 08:00 etc.</p>
  
  <p>Here is the code same `</p>
  
  <pre><code>  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
      TimePicker pn = (TimePicker) findViewById(R.id.tp_powernap);
  
      pn.setCurrentHour(7);
      pn.setCurrentMinute(0);
      System.out.println("timepicker erstellt");
      pn.setDescendantFocusability(TimePicker.FOCUS_BLOCK_DESCENDANTS);
      System.out.println("Tastatur geblockt");
      pn.setOnTimeChangedListener(StartTimeChangedListener);
      System.out.println("starttimechangedlistener");
      pn.setIs24HourView(false);
  }
  
  
  private TimePicker.OnTimeChangedListener StartTimeChangedListener =
      new TimePicker.OnTimeChangedListener() {
  
      public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
          updateDisplay(view, hourOfDay, minute);          
      }
  };
  
  private TimePicker.OnTimeChangedListener NullTimeChangedListener =
      new TimePicker.OnTimeChangedListener() {
  
      public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
  
      }
  };
  
  
  
  private void updateDisplay(TimePicker timePicker, int hourOfDay, int minute) {
      int nextMinute = 0;
      timePicker.setOnTimeChangedListener(NullTimeChangedListener);
      if (minute &gt;= 45 &amp;&amp; minute &lt;= 59) 
          nextMinute = 45;  
      else if (minute  &gt;= 30) 
          nextMinute = 30;
      else if (minute &gt;= 15) 
          nextMinute = 15;
      else if (minute &gt; 0) 
          nextMinute = 0; 
      else { 
          nextMinute = 45; 
      }
  
      if (minute - nextMinute == 1) {
          if (minute &gt;= 45 &amp;&amp; minute &lt;= 59) 
              nextMinute = 00; 
          else if(minute  &gt;= 30) 
              nextMinute = 45;
          else if(minute &gt;= 15) 
              nextMinute = 30;
          else if(minute &gt; 0) 
              nextMinute = 15; 
          else { 
              nextMinute = 15; 
          }
      }
  
      timePicker.setCurrentMinute(nextMinute);
  
      timePicker.setOnTimeChangedListener(StartTimeChangedListener);
  
  }
  </code></pre>