CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Time Stamp

 



Lesia
Deleted

Jun 11, 2000, 7:06 PM

Post #1 of 2 (426 views)
Time Stamp Can't Post

Hi, Everyone. On my chat script I would like the time and date to show up on each post behind the chatters name. Can anyone tell me how to set that up. Here's what the script has for time stamp.
Thanks, Lesia

$timestamp,# time stamp to track active users
$date, # date and time (adjustable for different timezones)

$SHOW_DATE = 0; # show date/time of messages

$HOURADJUST = 0; # add this to local hour
$TZONE = 'EST'; # to display this time zone
# # automatically adjusts for
# # daylight savings (EST -> EDT, etc)

$timestamp = time(); # get time stamp

$cur->param("timestamp", $timestamp); # get timestamp

$date = $entry->param("date") if($SHOW_DATE);

sub get_time {

my (
$sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$dst,
@months
);

@months = ("January","February","March","April","May","June","July",
"August","September","October","November","December");
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$dst)
= localtime(time()+$HOURADJUST*3600);
if ($hour < 10) {
$hour = '0'.$hour;
}
if ($min < 10) {
$min = '0'.$min;
}
if ($sec < 10) {
$sec = '0'.$sec;
}
$year += 1900; # Y2K OK!
$TZONE =~ tr/S/D/ if ($dst); # fix time zone string for daylight savings
return $timestamp = "$months[$mon] $mday, $year $hour:$min:$sec ($TZONE)";



Kanji
User / Moderator

Jun 13, 2000, 8:27 PM

Post #2 of 2 (426 views)
Re: Time Stamp [In reply to] Can't Post

Hi Lesia--

I'm a little confused by what you're actually trying to achieve, but you're taking the roundabout way of making the timestamp.

Instead, try something like ...

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

use POSIX qw();
sub get_time {
return POSIX::strftime(
"%B %d, %Y %T (%Z)",
localtime
);
}</pre><HR></BLOCKQUOTE>

... which should be the same or reasonably close to the timestamp format you were looking for.

Also, if you use localtime in scalar context (such as print scalar(localtime); it will actually return a human readable date string like "Wed Jun 14 00:29:07 2000".

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives