title: java calculate pregnancy algorithm
body: <p>hello I am trying to calculate how many days are left in a pregnancy term but I think my algorithm is incorrect</p>
  
  <pre><code>public int getDaysPregnantRemainder_new() {
      GregorianCalendar calendar = new GregorianCalendar();
     calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
     calendar.set(Calendar.SECOND, 0);
     long diffDays = 280 - ((getDueDate().getTime() - calendar.getTime()
    .getTime()) / (24 * 60 * 60 * 1000));
    return (int) Math.abs((diffDays) % 7);
     }
  </code></pre>
  
  <p>I am basing it off of a 280 day term, <code>getDueDate()</code> is a Date object and <code>getTime()</code> returns millisecond unix time</p>
  
  <p>On some real world days the number reported is off by one, sometimes, and I am starting to think my algorithm is just wrong, or the millisecond time get gradually further and further off, or the millisecond time is not precise enough, or the gregorian calendar function rounds weird.</p>
  
  <p>All in all I'm not sure, any insight appreciated</p>