Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

A PHP script to display the time in a given location UNIX
Okay, so I can never keep track of timezones, etc. I realize there may very well be a utility to do this but I'm not aware of what it is. So I wrote a quick one. It's just a php wrapper to the command:

% TZ=":Asia/Taipei" date

You can find all of the timezones in /usr/share/zoneinfo.

I put this script in my ~/bin, called it timein and made it executable (chmod 755 timein):

<?php  $city = $_SERVER['argv'][1];
$findresult = `find /usr/share/zoneinfo -iname $city`;

if (strlen($findresult) == 0)
  print "Sorry, city not found.\n";

$tzarray = split("\n", $findresult);
$tzfile = $tzarray[0];

$tzstring = ":" .  str_replace("/usr/share/zoneinfo/", "",$tzfile);

print `TZ="$tzstring" date`;
print "\n";
Usage is simple:
% timein london
Thu Jan 22 05:16:53 GMT 2004
If you wanted to add a city/state that isn't found (but you know of a neighboring file that is), you could probably either copy the file or softlink it in the terminal, e.g.:
% cd /usr/share/zoneinfo/US
share/zoneinfo/US% ls -la  (trimmed down)
-rw-r--r--   4 root  wheel   130 25 Sep 17:46 Hawaii
-rw-r--r--   3 root  wheel   549 25 Sep 17:46 Indiana-Starke
-rw-r--r--   2 root  wheel   811 25 Sep 17:46 Michigan

share/zoneinfo/US% sudo ln -s Michigan Flint
share/zoneinfo/US% ls -la Flint
lrwxr-xr-x   1 root  wheel     8 21 Jan 23:21 Flint -> Michigan

share/zoneinfo/US% timein flint
Thu Jan 22 00:21:40 EST 2004
Hmm, guess it's a bad time to call my folks...
  • Currently 3.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)

A PHP script to display the time in a given location | 1 comments | Create New Account
Click here to return to the 'A PHP script to display the time in a given location' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A PHP script to display the time in a given location
Authored by: jakacmar on Jan 30, '04 02:26:33PM
Not sure if I saw it here or somewhere else, but another way to use this is to simply make an alias in your .bashrc (or whatever Apple has decided to use) file (if you're using bash of course.) I always need to know the time in South Korea and so I set up and alias name "seoul" that looks like

alias seoul='env TZ=Asia/Seoul date'
remember to export the alias and then typing seoul at the command line will return the current time and date in South Korea.

[ Reply to This | # ]