New York
home > Time & Clocks Email

This page shows how to get exact time (atomic clock) and how to show time on your page.
On this page:
Code (Perl & Java)

 Main Sites home - top of the page - email

Try these (reload them to see how time changes): - my favorite, shows times in different zones - - - shows time in different countries and cities around the globe

Use Javascript to put time on your page: -

Browse many links related to time/clocks: - - Boulder Atomic Clock (a link from - The National Institute of Standards and Technology) - different ways

 Navy home - top of the page - email -
You can get text version here:
(you can parse it as you like to select the time you need).
It is updated every second.
( or you can get a GIF version of Universal Time
   by calling )

Here is how to convert from Universal Time:
More sophisticated example: the clock shows ~25-30 seconds live - and then stops.
ATTENTION: it works only in netscape browser (because Internet Explorer doesn't support this: Content-type:  multipart/x-mixed-replace)
You have to press SHIFT-RELOAD to (re)start this clock.
Clock requires Netscape
To add this clock to your home page, all you have to do is look at the HTML source for this page and copy a reference like this one:

<a href=""><img SRC=";ticks=60" ALT="Clock requires Netscape" BORDER=1 height=20 width=113></a>

You can substitute zone (time zone) for one from this list:
UTC - Universal Time
AST - Atlantic Standard/Daylight-Saving Time
EST - Eastern Standard/Daylight-Saving Time (this is the one used in the example)
EET - Eastern Standard Time (no Daylight-Saving Time)
CST - Central Standard/Daylight-Saving Time
MST - Mountain Standard/Daylight-Saving Time
MMT - Mountain Standard Time (no Daylight-Saving Time: Arizona)
PST - Pacific Standard/Daylight-Saving Time
YST - Alaska Standard/Daylight-Saving Time
HST - Hawaii Standard Time
GMT - Greenwich Mean Time/British Summer Time

 Misc. home - top of the page - email

 Code home - top of the page - email

Example getting time:


# ------------------------------------------
# read time from
# ------------------------------------------

use Socket;
use strict;

my $remoteServer = '';
my $serverTime;
my $proto = getprotobyname('tcp') || 6;
my $port = 8013;
my $serverAddr = (gethostbyname($remoteServer))[4];

# --------------------------
socket(SOCKET, PF_INET, SOCK_STREAM, $proto)
  or die("socket: $!");

my($packFormat) = 'S n a4 x8';   # Windows 95, SunOs 4.1+
#my($packFormat) = 'S n c4 x8';   # SunOs 5.4+ (Solaris 2)
connect(SOCKET, pack($packFormat, AF_INET(), $port, $serverAddr))
  or die("connect: $!");
$serverTime = <SOCKET>;
$serverTime = int ( 0.001 * $serverTime );

# --------------------------
printf("%-20s %8d %s\n", 
  $remoteServer, $serverTime - time, ctime($serverTime));
# --------------------------
printf("%-20s %8s %s\n",
  "localhost", 0, ctime(time()));
# --------------------------


# ------------------------------------------
sub ctime {

// select one of the hosts: NIST.GOV or TIME.GOV or BLDRDOC.GOV
int daytimePort = 8013;

// Get serverDateString using this method:

  private void GetServerDateString()
      Socket socket = new Socket(serverName, daytimePort);
      BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
      serverDateString = bufferedreader.readLine();
      if(serverDateString.equals("error")) {
        serverDateString = "";
        errorBoolean = true;
      } else { 
        errorBoolean = false; return;
    } // end of try
    catch(IOException _ex) {  serverDateString = "";  }
    errorBoolean = true;

// Then get a long value as number of ms from 1970:
      Long long1 = new Long(serverDateString);
      long l = long1.longValue();