I want some user (or some process) to have different time and date. Is it possible?

How can I do this?


What RunAsDate does is the following:

RunAsDate intercepts the kernel API calls that returns the current date and time (GetSystemTime, GetLocalTime, GetSystemTimeAsFileTime), and replaces the current date/time with the date/time that you specify.

Under Linux you have some options to accomplish the same thing:

  1. If you can get a Windows version of the program, you might be able to run RunAsDate under Wine (but watch out for a recent bug).

  2. Find a wrapper library to do this, or write your own. Some options are given below.

  3. Use a Virtual Machine. This is overkill, but since an OS in guest VM is completely separate from the underlying host, you can set it's system time to something completely different. It may be quicker to setup than the other options.

Option 2 can be accomplished by different methods, depending on the what you're trying to run. DaveParillo's answer below links to a DIY approach that explains the different methods and includes code for an executable. Some other options include:

  • I wish I could up vote this again - like the datefudge update! – DaveParillo Oct 25 '09 at 1:36

I had the same problem in finding an alternative to RunAsDate in Linux Ubuntu, and I came to this solution.

I created a launcher of the program that I want use with RunAsDate. If the software if you want to use is called Foo, create a file on your desktop called Foo.desktop, and modify it using gedit or a similar text editor. Then add to it the following lines of code:

[Desktop Entry]
Comment=Runs the Foo application
Exec=sh -c "sudo date --set '01 Jan 2008 12:00:00'; path/to/Foo; sudo timedatectl set-ntp no; sudo timedatectl set-ntp yes;"

You just need to change the Name, Comment and Icon information with your actual resources.

The Exec option changes the system date for the session while you are using the application, then when you finished it automatically resync the system date.

  • Does this modify the system time globally? As in, if I run Foo from your Foo.desktop, then open Bar (while Foo is still open), will Bar think the system time is '01 Jan 2008 12:00:00'? – LastStar007 Jul 25 '17 at 18:53

You can set the TZ to just about any value you want. The system time is unaffected, but the apparent time will change. This is not the same as intercepting the kernel, but requires no coding. Use (3 letter identifier)(offset from UTC h:m:s)[(summer time identifier)(summer offset from UTC h:m:s)]. For example: TZ=XXX[+-]hh:ss:ssYYY[+-]hh:ss:ss the second (summer) set is optional.

date; export TZ=FOO+23:11:17; date; export TZ=; date


Sat Oct 24 20:01:55 UTC 2009
Fri Oct 23 21:01:11 FOO 2009
Sat Oct 24 20:01:55 UTC 2009

Although I may regret this, here is an example program that you could compile to mod your kernel and completely fake out all or just selected programs about the date.

  • actually that's a great link, thx -- one of the comments to that post led me to the existing programs i mentioned in my edit. – quack quixote Oct 24 '09 at 21:32
  • Do not mess with the overall system time; it's pretty important that files are created with the correct date etc. – Lee B Oct 24 '09 at 22:01
  • Also, Timezones only support +/- 24 hours, afaik. The kernel mod for "selected programs" is still a good suggestion, but datefudge is probably the simpler method for most apps. – Lee B Oct 24 '09 at 22:03
  • the link mentions kernel modding but doesn't go into much detail; the code it provides uses the catch-a-system-call (run-in-container) method -- basically the same thing datefudge does. – quack quixote Oct 24 '09 at 22:15

Is this what you are trying to accomplish?

Linux, UNIX set the time zone on a per user basis

  • as the link title suggests, that only sets the timezone on a per user basis, but won't change the system time for that user. – quack quixote Oct 24 '09 at 18:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.