1212 Votes

VirtualBox: Change Date and Time

Tutorial by Stefan Trost | Last update on 2024-04-17 | Created on 2014-11-02

If you want to change the time in a guest system in VirtualBox, by default, you can experience the following behavior: After changing the clock of an operating system that was launched from VirtualBox, it does not take long before the time is returning to its original state. It seems as if there is no chance to change the time.

This is due to the automatic time synchronization with the host system. This means that by default the time of the host computer is always automatically adopted for the virtual machine. But what can you do if you want to run the virtual machine with a different date or time than the host system?

We have two options for this and should also pay attention to the points listed under "Important Requirements":

Change Settings via the Configuration File

Each virtual machine has two configuration files in which the settings for this machine are specified. You can find these files in the folder in which you have also stored the virtual machine as well as the image of the hard disk of the virtual machine.

The easiest way to find this folder is to right-click on the virtual machine in question in VirtualBox in the list on the left side of the main window and then select "Show in Explorer" from the context menu (you can also use the menu "Machine" > "Show in Explorer" when the virtual machine in question is just selected).

  • For example, the path to the folder can be "C:\Users\<user name>\VirtualBox VMs\<virtual machine name>", "C:\Documents and Settings\<user name>\.VirtualBox\Machines\<virtual machine name>", "C:\Users\<user name>\.VirtualBox\Machines\<virtual machine name>" or, of course, each other user defined folder.

The files are structured in XML format and have the file extension .vbox as well as .vbox-prev. The name before the extension is equal to the name of the virtual machine. So, for example ".vbox" and ".vbox-prev".

After opening the files in a text editor, you can add (or change) the following line in the section "". This line configurates whether the time should be taken from the host system:

With setting "value" to "0", the time is synchronized, if "value" is set to "1", there is no synchronization with the host system.

In order to prevent the automatic time synchronization in the future, accordingly, we have to set this value to 0 in both files and after that, we have to save the files.

Change Settings via the Command Line

Instead of changing the XML configuration files manually using a text editor, you can also perform the necessary changes from the command line. For this, you can enter the following command from the Terminal:

VBoxManage setextradata "" "VBoxInternal/Devices/VMMDev/0/Config/GetHostTimeDisabled" "1"

Of course, you have to insert the name of the virtual machine, you would like to change, into the command instead of "".

The tool VBoxManage is located in the installation folder of VirtualBox. So, you have to either run the command directly from the installation folder or you have to specify the full path to VBoxManage so that it works and the program is found and can be called.

By default, VirtualBox installs in the folder "C:\Program Files\Oracle\VirtualBox" on Windows. So, a full path call using this default installation path might look like this:

"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" setextradata "My Virtual Machine" "VBoxInternal/Devices/VMMDev/0/Config/GetHostTimeDisabled" "1"

If the name of your virtual machine contains spaces, it is important to remember not to forget to put the VM name in quotation marks. The same applies to the path of VBoxManage.exe, as the folder "Program Files" contains a space in its name.

Important Requirements

Undoubtedly, the most important prerequisite for the successful date and time change is changing the configuration files as described in the last sections. However, in order to make it work permanently and to maintain the set time, we have to consider two important things (regardless of our chosen method of configuration change):

  • On the one hand, we have to exit VirtualBox before making changes to the configuration files (not just the virtual machine we want to change, but the entire program),
  • on the other hand, we have to ensure that a possible automatic time synchronization is not active in the guest system.

We will look at these two points in more detail in the next two sections.

Important: Exit VirtualBox before

VirtualBox is reading the settings of the virtual machines at startup and it is storing its settings when closing the program. Therefore, when applying changes to the configuration, you have to close all running virtual machines as well as the application VirtualBox itself.

Otherwise the changes will not become active or they will even be overwritten with the next program close.

Important: Deactivate automatic Time Synchronization

Many operating systems have a built-in function that automatically synchronizes the system's date and time with the Internet. If this option is active, this can result in our guest system starting with our desired time that differs from standard time, but suddenly and unexpectedly it switches to the correct time.

The perfidious thing about that: Some of these synchronization functions do not check the time regularly (e.g. always when starting the system) but only from time to time. So, such a time check may occur, for example, only after the second or the third start of the virtual machine (especially if the virtual machines are not running for longer periods of time). This can mean that this "correction" is not immediately noticed and thus leads us into unexpected difficulties. In other words, there is not only the risk of a synchronization with the host system, but also the risk of a synchronization with the Internet. So, we always have to have both on our radar.

For this reason - in case your virtual machine is allowed to access the Internet and you want to use a custom time - you should always deactivate the automatic time synchronization or check whether it is active.

Where the automatic time synchronization can be configured depends of course on both, the operating system used as well as the version of the system. Below we would like to take a look at the procedure for Windows, Linux and the Mac:

  • On most Windows systems you can simply click onto the clock that can be found within the taskbar. If you perform this click with the right mouse button, you can then click on "Adjust date/time", while if you click with the left mouse button the setting is called "Change date and time settings" (the second variant is not available in all Windows versions). Alternatively, you can also open the Control Panel, then select "Clock and Region" or "Time, Language and Region" and then "Set the Time and Date". In the dialog that opens, go to the tab "Internet Time". If the option is active, it will say "The computer is set to automatically synchronize with time.windows.com" here, for example. To deactivate the synchronization, we can click on the button "Change Settings" in order to deactivate the option "Synchronize with an Internet time server". At this point you can also select the server and update the time using the button "Update Now".
  • On the Mac with one of the operating systems macOS or Mac OS it begins - as so often - via the menu with the apple symbol on the far left in the function bar at the top edge of the screen. From this menu select the entry "System Preferences". A window opens with all the settings categories available, from which you select the entry "Date & Time". The time settings then open with the three tabs "Date & Time", "Time Zone" and "Clock". We are only interested in the tab "Date & Time", where we can find right at the top of the tab the option "Set date and time automatically" as well as the possibility to set up a server such as time.apple.com, time.euro.apple.com or time.asia.apple.com for synchronization (as with Windows). To deactivate this synchronization, we simply have to uncheck "Set date and time automatically". The checkbox for this option may be grayed out. This is controlled by the small padlock at the bottom of the window, which is titled "Click the lock to make changes". If we do this, we must first enter our password. The lock then opens and with it the option to change the option to activate or deactivate the synchronization (the checkbox gets its color back and can therefore be operated in the same way as the drop-down box next to it). Furthermore, the padlock is then re-titled in "Click the lock to prevent further changes". If we do this once again, we can protect our settings from undesired changes made by other users.
  • If your guest system is a Linux system, due to the variety of different Linux distributions and different user interfaces, there may be several places where the time synchronization settings could be hidden - in case that they can be configured at all. In Ubuntu, the currently most popular and widely used Linux distribution, we can proceed as follows: First, we click on the gear symbol on the very right side of the top edge of the screen. A menu opens in which we click on the "System Settings" entry. In the window that opens, we click on "Time and Date". After that, under the world map, we will see the option "Set the Time" with the two choices "Manually" or "Automatically from the Internet". The "Manual" option is the setting of our choice to disable the automatic time synchronization. Of course, the options may have a different name in other distributions or even versions of Ubuntu, but the procedure should be similar.

If we don't let our virtual machine access the Internet at all, we can of course skip this step, since in this case VirtualBox will ensure that the guest system cannot reach the time synchronization server anyway.

ReplyPositiveNegativeDateVotes
00 Votes

I thank you for these instructions, which are understandable even to me, but they do not solve my problem with the time update.

Is it due to Linux (Ubuntu, more precisely Mint 17.1) or to the Oracle Vbox 4.3.18_Ubuntu r956516 that the vbox file is constantly being freed from the line I entered or the rights to it are being reset, so that I can't vbox prevent from changing this file back?
2015-02-04 at 18:47

ReplyPositive Negative
11 Vote

Have you closed the entire VirtualBox program and not just the currently running virtual machines?

If you make changes to the file while VirtualBox is still running, exactly this overwriting occurs.

So, first make sure that the entire program is closed, then make the changes to the files and then restart VirtualBox again.
2015-02-05 at 14:01

Positive Negative
00 Votes

Thank you and yes, that's what I thought (at least until now), because it just worked as you described.

I named my vbox version, my OS is Linux 3.13.0-37 Ubuntu SMP x86_64. It didn't work several times that day, but I didn't try restarting because that wasn't appropriate at the time.

I therefore suspect that, similar to the mySQL daemon, which could no longer be removed later that evening, an incomplete termination occurred. I never had any problems with vbox, so I didn't check that all processes had ended properly, I just ended the programs.
2015-02-07 at 11:11

Positive Negative
Reply
00 Votes

Thank you very much for this helpful guide.

I decided to edit the configuration files manually. Worked :)
2015-09-20 at 16:34

ReplyPositive Negative
00 Votes

The path to the XML file has changed (I think), it is now:

C:/Users/<username>/VirtualBox VMs/<nameofvm>
2017-03-19 at 22:22

ReplyPositive Negative
00 Votes

As I said, the directory can be freely chosen. My VMs are even not on the C drive, as an example, others don't even use Windows.

Therefore, you should right-click on the VM and select "Show in Explorer". Nevertheless, I have listed some typical paths in the tutorial.
2017-03-20 at 14:44

Positive Negative
Reply
00 Votes

Works wonderfully and is also very well explained and described.

Thank you for this very good tutorial!!! :)
2019-01-06 at 10:28

ReplyPositive Negative
11 Vote

This works sometimes.

I think there must be a bug.

Sometimes my virtual machine is keeping its own date and time sometimes it will revert to the date and time of the system. I have double checked the settings and they are correct. I used the command and looked afterwards in the settings files to see if the settings were ok.
2021-07-25 at 22:57

ReplyPositive Negative
22 Votes

Some operating systems are checking and updating their time from the internet by default. When you let the system start with an individual time, that time might then be overwritten with the current time at startup of the VM again after the time sync. Maybe this is the reason for that behavior.

Usually the operating systems are providing an option that can be deactivated to prevent that automatic time synchronization.

I have added a section to the tutorial that describes this issue and explains how to turn off this synchronization.
2021-07-25 at 23:44

Positive Negative
Reply
00 Votes

Works perfect! Thanks!

I changed it via VBoxManage.
2021-09-02 at 13:37

ReplyPositive Negative
Reply

About the Author

AvatarYou can find Software by Stefan Trost on sttmedia.com. Do you need an individual software solution according to your needs? - sttmedia.com/contact
Show Profile

 

Related Topics

PHP: Current Date and Time

Tutorial | 0 Comments

PHP: Determine Week Number

Tutorial | 0 Comments

Change Date of File

Tutorial | 0 Comments

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.