CHAPTER 9 – DATE HANDLING – Showing the Local Time in Other Time Zones

S o m e - times, you want to show a formatted time in the current time zone and in other time zones as well. The following script shows a full textual date repre- sentation for the U.S., Norway, the Netherlands, and Israel:

<?php echo strftime("%cn");

echo "nEST in en_US:n"; setlocale(LC_ALL, "en_US"); putenv("TZ=EST"); echo strftime("%cn");

echo "nMET in nl_NL:n"; setlocale(LC_ALL, "nl_NL"); putenv("TZ=MET"); echo strftime("%cn");

echo "nMET in no_NO:n"; setlocale(LC_ALL, "no_NO"); putenv("TZ=MET"); echo strftime("%cn");

echo "nIST in iw_IL:n"; setlocale(LC_ALL, "iw_IL"); putenv("TZ=IST"); echo strftime("%cn"); ?> Figure 9.4 shows its output. Fig. 9.4 March 1 in different locales. Note: You need to have the locales and time-zone settings installed on your system before this will work. It is a system-dependent setting and not every- thing is always available on your system. If you're a Mac OS X user, have a look at http://www.macmax.org/locales/index_en.html to install locales.

Post Comment
Login to post comments