title: Override Java System.currentTimeMillis for testing time sensitive code
body: <p>Is there a way, either in code or with JVM arguments, to override the current time, as presented via <code>System.currentTimeMillis</code>, other than manually changing the system clock on the host machine?</p>
  <p>A little background:</p>
  <p>We have a system that runs a number of accounting jobs that revolve much of their logic around the current date (ie 1st of the month, 1st of the year, etc)</p>
  <p>Unfortunately, a lot of the legacy code calls functions such as <code>new Date()</code> or <code>Calendar.getInstance()</code>, both of which eventually call down to <code>System.currentTimeMillis</code>.</p>
  <p>For testing purposes, right now, we are stuck with manually updating the system clock to manipulate what time and date the code thinks that the test is being run.</p>
  <p>So my question is:</p>
  <p>Is there a way to override what is returned by <code>System.currentTimeMillis</code>?  For example, to tell the JVM to automatically add or subtract some offset before returning from that method?</p>