title: How to obtain the start time and end time of a day?
body: <p>How to obtain the start time and end time of a day?</p>
  
  <p>code like this is not accurate:</p>
  
  <pre><code> private Date getStartOfDay(Date date) {
      Calendar calendar = Calendar.getInstance();
      int year = calendar.get(Calendar.YEAR);
      int month = calendar.get(Calendar.MONTH);
      int day = calendar.get(Calendar.DATE);
      calendar.set(year, month, day, 0, 0, 0);
      return calendar.getTime();
  }
  
  private Date getEndOfDay(Date date) {
      Calendar calendar = Calendar.getInstance();
      int year = calendar.get(Calendar.YEAR);
      int month = calendar.get(Calendar.MONTH);
      int day = calendar.get(Calendar.DATE);
      calendar.set(year, month, day, 23, 59, 59);
      return calendar.getTime();
  }
  </code></pre>
  
  <p>It is not accurate to the millisecond.</p>