Archive for April, 2013

PHP find time difference between two countries by country code

April 28, 2013 1 comment

To calculate time difference between two countries following code can be used:

i will calculate time difference between United States (New York) and Jamaica

Origin: United States
Destination: Jamaica

Find Jamaica time zone

(note if you need accurate result and/or there are more than 1 timezone in calculated country you need to use city/province code with geoip_time_zone_by_country_and_region() function as second parameter to get timezone)

$timezone = geoip_time_zone_by_country_and_region("JM");

Find offset between destination time zone and origin timezone

$offset = get_timezone_offset($timezone, 'America/New_York');

Our custom get_timezone_offset() function that we use to calculate offset between 2 locations:

function get_timezone_offset($remote_tz, $origin_tz = null) {
    if ($origin_tz === null) {
        if (!is_string($origin_tz = date_default_timezone_get())) {
            return false;
    $origin_dtz = new DateTimeZone($origin_tz);
    $remote_dtz = new DateTimeZone($remote_tz);
    $origin_dt = new DateTime("now", $origin_dtz);
    $remote_dt = new DateTime("now", $remote_dtz);
    $offset = $origin_dtz->getOffset($origin_dt) - $remote_dtz->getOffset($remote_dt);
    return $offset;

Add offset to current time:

$offset_time = time() - $offset;

Print current time and timezone of destination country

echo "Time in JM: ".date('Y-m-d H:i', $offset_time) ." ($timezone)</br>";

Convert offset to hour format (default is seconds)


Print time difference in hours:

if ($of > 0){
   echo "JM is ".abs($of)." hours behind";
}elseif($of < 0){
   echo "JM is ".abs($of)." hours ahead";
   echo "There is no time difference";

Note:Make sure you set your local time zone at the beginning of you code otherwise time() function results will be in accurate


Check out the new version

**get_timezone_offset function is taken from


Update Lenovo x120e bios on linux (mouse does not work on linux)

April 28, 2013 Leave a comment

There is a problem with Lenovo x120e bios which causes mouse (trackball and/or pad,external mouse) not to function on linux. Can not click on links, menus etc…

Seems like this problem does not occur on freebsd.


Download latest bios image from Lenovo support page

Download geteltorito to extract  boot image from iso image

chmod +x geteltorito
./geteltorito 8duj10uc.iso > bios.img

Write bios image to usb drive. If usb is mounted umount before writing bios image and do not use drive number

dd if=bios.img of=/dev/sdb bs=512K

restart laptop and boot from usb drive  follow instructions on the screen.