I just need to set the date temporarily. I run this

date 051918002010.00

and it sticks for just 5 seconds or so. Then it syncs with the time server. I have tried:

ps aux | grep ntp

but there is nothing there.

I need a correct answer now, more than a more detailed answer later :)

Edit: As answerers quickly discovered, my Ubuntu is running in a VirtualBox, which turned out to be relevant for some versions of the answer. Thanks to everybody.

  • Why you are trying to do this, what is the purpose? – Jeffrey Vandenborne Dec 15 '09 at 21:40
  • 1
    development, simulating situations. – Dan Rosenstark Dec 15 '09 at 21:54

It sounds like you're really looking for a way to run a program so that the program thinks it's running under a different date and time.

An earlier question was asked about this: Linux RunAsDate analogue? Below is the answer I gave there. Note you seem to be attempting Option 3.

The ntpdate package isn't a daemon and should not be updating your system time automatically (it should run once at boot and no more). I'm not overly familiar with VirtualBox, but I'd guess you've either got ntpd installed or the VirtualBox Guest Additions are syncing the time directly from the host OS, in which case you'll need to disable them, or use one of the wrapper libraries mentioned below in Option 2.

Update: It looks like the VirtualBox Guest Additions install /usr/sbin/vboxadd-timesync -- I'd guess this is the executable that syncs the guest clock with that of the host. Check to see if it's installed a startup script (possibly /etc/init.d/vboxadd-timesync); if so, you can stop the sync with sudo /etc/init.d/vboxadd-timesync stop. If no startup script, you can probably just kill the process.

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:

  • sudo /etc/init.d/vboxadd-timesync stop worked! Thanks so much ~quack – Dan Rosenstark Dec 16 '09 at 20:15
  • Wow, datefudge works perfectly on Ubuntu as well. Very sweet. Thanks again! – Dan Rosenstark Dec 16 '09 at 20:22
  • 2
    Just for my notes if you don't mind: datefudge "Wed Dec 16 15:20:28 EST 2008" ruby script/console – Dan Rosenstark Dec 16 '09 at 20:24
  • The only thing missing at the beginning of the answer is: "Don't be evil when using this info". – Radu Maris Nov 19 '13 at 18:24

Since your comment response to Dan McG seems to indicate that you're running Ubuntu as a VirtualBox guest, if you've installed the VirtualBox guest additions, then they will automatically sync the guest's time with the host's.

ps -ef | grep VBoxService

should show the VirtualBox guest additions service running.

You could then try:

sudo /etc/init.d/vboxadd-service stop

to stop it until reboot.

  • I'll try cutting the network connection on the guest then. – Dan Rosenstark Dec 15 '09 at 21:53
  • Smart thinking there, everything is so clear now, cheers! – Jeffrey Vandenborne Dec 15 '09 at 21:55
  • @Yar, I'm not sure it goes through the virtual network connection on the guest. It probably gets the hosts' system clock value through the VirtualBox process. – Nick Meyer Dec 15 '09 at 21:56
  • @Nick Isn't there a config file or configuration dialog available for the vbox guest additions? Maybe he can change the time syncing there. coming from vmware, I don't got a lot of experience with this. – Jeffrey Vandenborne Dec 15 '09 at 22:01
  • this was great stuff, but: 1) While I am running as a VirtualBox guest, the VBoxService is not loaded (I never did the extensions, I guess) 2) vboxadd-service does not exist 3) even killing both network connections causes the time to be restored in a matter of seconds – Dan Rosenstark Dec 15 '09 at 22:03

Quick Answer: Disconnect your network connection :)

  • I'm not even sure how to do that, since it seems to be getting time from... the VirtualBox host? Or perhaps... not sure, but disconnecting the Internet did not help. – Dan Rosenstark Dec 15 '09 at 21:41
  • If you're using a wired network, check out the network icon in the top panel (I assume you didn't tweak your desktop) click it and choose disconnect. – Jeffrey Vandenborne Dec 15 '09 at 21:45
  • Problem is that nntp continues, it seems, as it does gradual updates. In any case, the time sync does not stop without internet connectivity. – Dan Rosenstark Dec 15 '09 at 21:48
  • sudo apt-get remove ntpdate – Jeffrey Vandenborne Dec 15 '09 at 21:52

You could also look at 'libfaketime', which is packaged in Ubuntu/Debian.

It allows you to fake system time for a program without having to change the system-wide time (by intercepting the system calls by using LD_PRELOAD)


You can run VBoxManage setextradata <guest-vm-name> "VBoxInternal/Devices/VMMDev/0/Config/GetHostTimeDisabled" 1 on your host OS to disable automatic time sync.

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.