Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to retrieve user's local time? 1

Status
Not open for further replies.

alan123

MIS
Oct 17, 2002
149
US
I have written a script to track user's IP address, how can I retrieve user's local machine time(not server's system time), is there any way to do this?

thanks

michael
 
The only way I know is:
Code:
use CGI qw/:standard :shortcuts form/;

print header,
    start_html,
    form(
        "What's the time?",
        textfield( -name=>'time', -length=>6 ),
        br,
        submit( -name=>'Thanks!')
    ),
    end_html;

Yours,


fish ;-)


"As soon as we started programming, we found to our surprise that it wasn't as easy to get programs right as we had thought. Debugging had to be discovered. I can remember the exact instant when I realized that a large part of my life from then on was going to be spent in finding mistakes in my own programs."
--Maurice Wilkes
 
You could use javascript to set a hidden field. the approrpiate JS function to get the current time would be:

function GMTnow (GMT) {
var time = new Date();
hrs = time.getHours();
mins = time.getMinutes();
GMT = (hrs*60 + mins) - time.getTimezoneOffset();
return GMT;
}

Barbie
Leader of Birmingham Perl Mongers
 
Barbie,

Sharp; * 4 u

Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
I know it isn't perl, but I just grabbed this off one of my pages. You could, in the onload portion, alter it to submit the users local time and refresh the screen to the actual URL you want to display. I hate 'auto-click' pages, but it may have to do ;)

<script>
<!--
function show2(){
if (!document.all)
return
var Digital=new Date()
var hours=Digital.getHours()
var minutes=Digital.getMinutes()
var seconds=Digital.getSeconds()
var dn=&quot;AM&quot;
if (hours>12){
dn=&quot;PM&quot;
hours=hours-12
}
if (hours==0)
hours=12
if (minutes<=9)
minutes=&quot;0&quot;+minutes
if (seconds<=9)
seconds=&quot;0&quot;+seconds
var ctime=hours+&quot;:&quot;+minutes+&quot;:&quot;+seconds+&quot; &quot;+dn
tick2.innerHTML=&quot;<b style='fontsize:20;color:black;'>&quot;+ctime+&quot;</b>&quot;
setTimeout(&quot;show2()&quot;,1000)
}
window.onload=show2
</script>

-MikeyG
 

hello,

how do i get the server's time and display it on my page?

pls help. i'm a newbie. =(


 
#R17

#use the localtime function in a script;

sub currentTime {
my $obj = shift;
my ($seconds, $minutes, $hours, $day, $mon, $yr, $wday, $yday, $isdst)=localtime();
if ($minutes eq &quot;1&quot; || $minutes eq &quot;2&quot; || $minutes eq &quot;3&quot; ||
$minutes eq &quot;4&quot; || $minutes eq &quot;5&quot; || $minutes eq &quot;6&quot; ||
$minutes eq &quot;7&quot; || $minutes eq &quot;8&quot; || $minutes eq &quot;9&quot;){
$minutes = &quot;0&quot;.&quot;$minutes&quot;;}
my $time=&quot;$hours:$minutes:$seconds&quot;;
return $time;
}

#I really should put a regex in for the single digit stuff #but this works..


haunter@battlestrata.com
 
Another way to do it is;

Code:
sub currentTime {
my $obj = shift;
my ($seconds, $minutes, $hours, $day, $mon, $yr, $wday, $yday, $isdst)=localtime();
my $time=sprintf(&quot;%0.2d&quot;,$hours).&quot;:&quot;.sprintf(&quot;%0.2d&quot;,$minutes).&quot;:&quot;.sprintf(&quot;%0.2d&quot;, $seconds);
return $time;
}
--Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top