Can I change the current date and time for a specific process?

Viewed 1611

Is there a way to change the date and time seen by a specific process as opposed to the entire computer (i.e. the time returned by time() in C, by DateTime.Now in C#, by datetime.now() in Python, by new Date() in JavaScript, by System.currentTimeMillis() in Java, etc.)?

For instance, is there a way to fool a program into thinking it's midnight while it's 7 AM on the rest of the computer, or to make it think it's Christmas or Leap Day while the system clock shows July 18th?

An applicable situation would be when you're writing unit tests and you want to quickly test any special behavior the program has on Christmas or on Leap Day or on the demo's expiration date, and you want to test this behavior without having to use the date changing function in the OS and interfere with programs that rely on the date being correct (much less forcing me to have superuser privileges over the computer).

4 Answers
Related