I want some user (or some process) to have different time and date. Is it possible?
How can I do this?
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
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:
Find a wrapper library to do this, or write your own. Some options are given below.
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:
datefudge, available in Debian/Ubuntu repositories and other places.
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] Name=Foo 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;" Icon=path/to/icon.png Terminal=true Type=Application StartupNotify=true
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.
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.
Is this what you are trying to accomplish?