No, Time::Local would return the server's local time, not the client's, since perl is a server-side language. To find the client's local time (without them directly inputting it), you have to use a client-side language, such as javascript, store it in a hidden input field, and then have it submitted when they submit the form. You could try something like:
<form name="theform" action="getmytime.pl"> <input type="hidden" name="user_localtime"> </form> <script language="Javascript1.2"> function set_user_localtime() { // find out if the script has already been called if ( typeof already_submitted == "undefined" ) { // create new date var datevar = new Date(); var timestring = datevar.toLocaleString(); // set the hidden field's value to the local time document.theform.user_localtime.value=timestring; // submit the form document.theform.submit(); } return 1; } </script> <body onLoad="set_user_localtime())">
(the submitted value will look something like this: 08/18/01 17:28:35) Then you need a perl script that handles that. The perl script could re-write the page, but make sure that you also have something like that assures that the script isn't called again, and is printed right after the content-type header:
# tells the javascript that the script as already been run print "<script>var already_submitted=1;</script>";
Finally, you can find their offset by formatting the submitted value to be similar to perl's localtime like so:
use CGI; $query = CGI::new; $user_localtime = $query->param("user_localtime"); @user_l = split (' ', $query); @user_time = split (':', $u_l[1]); @server_localtime = localtime; $offset = $user_time[0] - $server_localtime[2]; print $offset;
$offset will be the difference between the server's local time and the user's local time.

In reply to Re: Client's time/date? by jryan
in thread Client's time/date? by the_mind_

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.