Version 11 of Worldtime-clock

Updated 2013-09-20 10:08:28 by HJG

HJG 2012-02-02 Small and simple program to show the time at some selected places around the world. With some tweaks to the tcl-console.

 # Worldtime-clock - http://wiki.tcl.tk/14375
 # HaJo Gurt - 2012-02-02

  catch {console show}
  catch {wm withdraw .}
 #console eval {wm geometry . 56x25}
 # Resize console & position it at top-right corner on screen, for 1024x768:
  console eval {wm geometry . 56x25+550+0} 
  console eval {.console config -bg grey -fg blue}

  proc q {} {exit}

  proc w {} {
    puts "Time around the world:"
    foreach tz {
       :Pacific/Honolulu
       :America/Los_Angeles        
       :America/Chicago
       :America/New_York
       :UTC
       :Europe/Berlin
       :Africa/Cairo
       :Europe/Moscow
       :Asia/Tokyo
       :Australia/Canberra }  {
         set td [clock format [clock seconds] \
            -format "%H:%M:%S  %Y-%m-%d  %a  %z" -timezone $tz] 
         puts [format "%-22s %s" $tz $td] 
    }
  }

  console title "Worldtime - w to refresh, q to quit"
  w

 #.

Result:

Time around the world:
:Pacific/Honolulu      10:25:00  2012-02-13  Mon  -1000
:America/Los_Angeles   12:25:00  2012-02-13  Mon  -0800
:America/Chicago       14:25:00  2012-02-13  Mon  -0600
:America/New_York      15:25:00  2012-02-13  Mon  -0500
:UTC                   20:25:00  2012-02-13  Mon  +0000
:Europe/Berlin         21:25:00  2012-02-13  Mon  +0100
:Africa/Cairo          22:25:00  2012-02-13  Mon  +0200
:Europe/Moscow         23:25:00  2012-02-13  Mon  +0300
:Asia/Tokyo            05:25:00  2012-02-14  Tue  +0900
:Australia/Canberra    07:25:00  2012-02-14  Tue  +1100

BTW, there is a worldtimeclock buried in the tk-demos that come with ActiveTcl, look for "Paned Windows and Notebooks / Themed nested panes".

Here is an extended version that offers a "running" clock:

 # Worldtime-clock2 - http://wiki.tcl.tk/14375
 # HaJo Gurt 
 # 2012-02-02: worldclock1
 # 2013-09-13: c1,c2, t1,t2, every, r,s : colors, titles, run/stop

  catch {console show}
  catch {wm withdraw .}
 #console eval {wm geometry . 56x25}
 # Resize console & position it at top-right corner on screen, for 1024x768:
  console eval {wm geometry . 56x25+550+0} 

  proc q {} {exit}

  proc every {ms body} {
    if 1 $body
    after $ms [list after idle [info level 0]]
  }

  proc c1 {} { 
    console eval {.console config -bg grey -fg blue}
  }
  proc c2 {} { 
    console eval {.console config -bg grey -fg red}
  }
  proc t1 {} { 
    console title "Worldtime2 - w to refresh, q to quit / r: run, s: stop"
    puts "Worldtime2 - w to refresh, q to quit / r: run, s: stop\n"
  }
  proc t2 {} { 
    console title "Worldtime2 - s to stop, q to quit"
  }
  proc r {} {t2; every 1000 {w}}
  proc s {} {foreach id [after info] {after cancel $id}; t1 }


  proc w {} {
    puts "Time around the world:"
    foreach tz {
       :Pacific/Honolulu
       :America/Los_Angeles        
       :America/Chicago
       :America/New_York
       :UTC
       :Europe/Berlin
       :Africa/Cairo
       :Europe/Moscow
       :Asia/Tokyo
       :Australia/Canberra }  {
         set ::cs [clock seconds]
         if {[expr { $::cs % 10}] == 0} {c2} else {c1}
         set ::td [clock format $::cs \
            -format "%H:%M:%S  %Y-%m-%d  %a  %z" -timezone $tz] 

         puts [format "%-22s %s" $tz $::td] 
    }
  }

  c1; t1
  w

 #.

See also: Wallclock - clock format - timezone - Windows wish console - after - every