7

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

How can I do this?

5 Answers 5

13

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:

1
  • I wish I could up vote this again - like the datefudge update! Oct 25, 2009 at 1:36
2

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.

2
  • 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'? Jul 25, 2017 at 18:53
  • or just on console: sudo date --set '01 Jan 2008 12:00:00'; path/to/Foo; sudo timedatectl set-ntp no; sudo timedatectl set-ntp yes; Dec 8, 2019 at 3:35
1

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

returns:

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.

4
  • 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. Oct 24, 2009 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, 2009 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, 2009 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. Oct 24, 2009 at 22:15
0

Is this what you are trying to accomplish?

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

1
  • 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. Oct 24, 2009 at 18:02
0

I have tried this and tinker a little bit with it and this is how it works for me:

  1. First:
[Desktop Entry]
Name=Foo 
Comment=Runs the Foo application
Exec=sh -c "sudo date --set '01 Jan 2008 12:00:00'; path/to/Foo#see the default launcher if it is already made#; sudo timedatectl set-ntp no;"
Icon=path/to/icon.png
Terminal=true
Type=Application
StartupNotify=true
  1. Second Create a separate launcher with this code to set the time back to the default network
timezone: 
timedatectl set-ntp yes

You can run the program and after it ran you can run the second launcher to reset your time to the default while your program is already running. I tried to make one launcher with the sleep command so I can make the second part of it run 10 seconds after the first part but didn't work for me. All of this I ran on Linux Mint and it works fine.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .