in reply to NIST Atomic Clock Time
#!/usr/bin/perl use strict; use warnings; use LWP::UserAgent; # Modify the args as needed for your locale my $URI = 'http://www.time.gov/timezone.cgi?Eastern/d/-5'; MAIN: { # Create user agent my $ua = LWP::UserAgent->new; # Create request my $req = HTTP::Request->new(GET => $URI); # Get remote time, and monitor local (computer) time my ($res, $t1, $t2); do { # Get local time $t1 = time(); # Execute request $res = $ua->request($req); # Read local time again $t2 = time(); # Loop if the two measures of local time differ } while ($t1 != $t2); # Check response if ($res->is_success) { # Extract remote time my ($hh, $mm, $ss) = $res->content =~ />(\d{1,2}):(\d{2}):(\d{ +2})</; if (defined($ss)) { # Output remote time printf("Remote time: %02d:%02d:%02d\n", $hh, $mm, $ss); # If local and remote times differ, then output local time + as well if ($ss != $t1 % 60) { ($ss, $mm, $hh) = (localtime($t1))[0-2]; printf("Local time : %02d:%02d:%02d\n", $hh, $mm, $ss) +; } } else { print("ERROR: Time not found in returned results.\n"); } } else { print('ERROR: ', $res->status_line, "\n"); } } exit(0); # EOF
|
|---|