World clock command line?

Is there a script to display simple world clocks (time in different places around the world) on the * nix terminal?

I was thinking of writing a quick Python script, but I have a feeling that I will work more than I think (for example, due to the configuration and output format) - not to mention rethinking the wheel ...

+5
source share
6 answers

I have this bourne script shell:

#!/bin/sh

PT=`env TZ=US/Pacific date`
CT=`env TZ=US/Central date`
AT=`env TZ=Australia/Melbourne date`

echo "Santa Clara    $PT"
echo "Central        $CT"
echo "Melbourne      $AT"
+14
source

I never thought about it, but it's not very hard to do.

#!/bin/sh
# Command-line world clock

: ${WORLDCLOCK_ZONES:=$HOME/etc/worldclock.zones}
: ${WORLDCLOCK_FORMAT:='+%Y-%m-%d %H:%M:%S %Z'}

while read zone
do echo $zone '!' $(TZ=$zone date "$WORLDCLOCK_FORMAT")
done < $WORLDCLOCK_ZONES |
awk -F '!' '{ printf "%-20s  %s\n", $1, $2;}'

Given the input file:

US/Pacific
Europe/London
Europe/Paris
Asia/Kolkatta
Africa/Johannesburg
Asia/Tokyo
Asia/Shanghai

I got the result:

US/Pacific             2008-12-15 15:58:57 PST
Europe/London          2008-12-15 23:58:57 GMT
Europe/Paris           2008-12-16 00:58:57 CET
Asia/Kolkatta          2008-12-15 23:58:57 GMT
Africa/Johannesburg    2008-12-16 01:58:57 SAST
Asia/Tokyo             2008-12-16 08:58:57 JST
Asia/Shanghai          2008-12-16 07:58:57 CST

I was fortunate that it took less than a second to run and did not cross the 1 second border.

( , GMT. / .)

+6

, , , , :

#!/bin/sh

# Show date and time in other time zones

search=$1

zoneinfo=/usr/share/zoneinfo/posix/
format='%a %F %T'

find -L $zoneinfo -type f \
    | grep -i "$search" \
    | while read z
      do
          d=$(TZ=$z date +"$format")
          printf "%-34s %23s\n" ${z#$zoneinfo} "$d"
      done

:

$ /usr/local/bin/wdate bang
Africa/Bangui                      Fri 2009-03-06 11:04:24
Asia/Bangkok                       Fri 2009-03-06 17:04:24
+2

Python, Pytz:

http://pytz.sourceforge.net/

, .

, , Google, , * nix. "python world clock", , .

+1

./cpython-2.7/Demo/curses/tclock.py, tclock.c - 1994 ASCII / curses, ncurses. :

$ TZ=Europe/Paris python tclock.py

.

+1

script mivk. , script bash, bourne . , :

#!/usr/bin/env bash                                                             

# Show date and time in other time zones, with multiple args                                        


elements=$@

zoneinfo=/usr/share/zoneinfo
format='%a %F %T'

for search in ${elements[@]}; do

  find $zoneinfo -type f \
      | grep -i "$search" \
      | while read z
        do
            d=$(TZ=$z date +"$format")
            printf "%-34s %23s\n" ${z#$zoneinfo} "$d"
        done
done

:

/usr/local/bin/wdate Sydney Stockholm /Australia/Sydney Fri 2015-08-14 05:54:26 /Europe/Stockholm Thu 2015-08-13 21:54:26

0

All Articles