0

I have an application and have used java.util.Date() function to get the current time.

Now I have a requirement to change the current date to a back date for some particular cases.

Suppose, I want to go to a back date and then do some transactions.

Is it possible to change the system time to a back date for a particular session?

Jean-François Corbett
  • 37,420
  • 30
  • 139
  • 188
Probal Basak
  • 92
  • 4
  • 12
  • Changing the system date in order to back-date a transaction sounds like a terrible idea. Leave the system clock alone and keep track of the transaction's date in your logic. – Kevin Panko Apr 15 '14 at 17:52

1 Answers1

0

I would use a long for the time as all Date does is wrap that. There is no system date which can be changed programatically. What you can do is to have your own method for getting the time which can be changed as required. I suggest having an interface for getting the time and having multiple implementations, one for using System.currentTimeMillis() and another which is settable.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130