Change BIOS time of a VirtualBox VM

Firstly, go here and tweak this script, adding the date you need. Click run. The result displayed is the number of milliseconds that you need to shave off the current bios time.

// Now
$time = time();
// Date you want
$date = new DateTime('2014-09-18');
$newTime = $date->format('U');
// Copy paste the result into the command below
echo ($time - $newTime) * 1000;

Make sure the box is shut down. Now in your terminal, run these:

VBoxManage setextradata "NAME_OF_VM_HERE" "VBoxInternal/Devices/VMMDev/0/Config/GetHostTimeDisabled" 1
VBoxManage modifyvm "NAME_OF_VM_HERE" --biossystemtimeoffset PASTE_NUMBER_HERE

That’s it! VM is now running in the past.


Jan 1st 1970! Unix time conversions

If you store dates in MySQL in unix time format, its nice to be able to quickly convert it back!

In Linux, the terminal command can either be:

$ date -d @1344262406
Mon Aug  6 15:13:26 BST 2012


$ date -u --date="1970-01-01 1344262406 sec GMT"
Mon Aug  6 14:13:26 UTC 2012

Guess which one I prefer? Note the timezone differences.

On a Mac (or any other Unix), you can try this:

$ date -r 1282368345
Sat Aug 21 07:25:45 CEST 2010
$ date -r 1282368345 +%Y-%m-%d