views:

36

answers:

2

Hey Guys,

What is the quickest way to internationalise a php webapp?

We need to be able to change all times & dates based on a timezone selected by a user...

[edit: this application is already in production. I've been given the task of making it usable on an international level asap.]

A: 

From http://www.php.net/manual/en/function.date-default-timezone-set.php

<?php
date_default_timezone_set('America/Los_Angeles');

$script_tz = date_default_timezone_get();

if (strcmp($script_tz, ini_get('date.timezone'))){
    echo 'Script timezone differs from ini-set timezone.';
} else {
    echo 'Script timezone and ini-set timezone match.';
}
?>

List of timezones: http://www.php.net/manual/en/timezones.php

Galen
+1  A: 

1) Store all your dates in UTC time. (Technically any single timezone would work, but it's less complicated to stick with UTC.)

2) Call date_default_timezone_set() with the user's time zone.

3) Use date() on those UTC times / UNIX timestamps.

The user will then see all dates and times with their timezone settings.

Make sure when creating dates that you use gmdate() and set the MySQL timezone to be UTC as well.

konforce