Gossamer Forum
Home : General : Perl Programming :

How to display time?

Quote Reply
How to display time?
How would the code below look if I wanted it to display Eastern time, and have it display 12 hours am and pm, without showing the hours and time like 23:45:07?
Code:
print ("Content-type: text/html\n\n");

($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time - 10700);

------------------
Patrick Chukwura
Nytesoft WebSolutions
nytesoft.hypermart.net
Quote Reply
Re: How to display time? In reply to
Alex, do you know the answer to this, since this bulletin board displays the time that way?

------------------
Patrick Chukwura
Nytesoft WebSolutions
nytesoft.hypermart.net
Quote Reply
Re: How to display time? In reply to
This is the cut from UBB code:

Code:
#format time option 1
if ($TimeFormat eq "24HR") {
@timearray = split(/ /, $theTime);
chomp($timearray[1]);
($gethour, $getmin) = split(/:/, $timearray[0]);

if ($timearray[1] eq "PM") {
if ($gethour < 12) {
$gethour = ($gethour + 12);
}
}

if ($AMpm eq "AM") {
if ($gethour == 12) {
$gethour = "0";
}
}
$gethour = sprintf ("%2d", $gethour);
$gethour =~tr/ /0/;
$getmin = sprintf ("%2d", $getmin);
$getmin =~tr/ /0/;

$FormatTime = "$gethour:$getmin";
} else {
$FormatTime = "$theTime";
}

this way this UBB displays time.

Is this what you asked for?

Regards,

Pasha

------------------
webmaster@find.virtualave.net
http://find.virtualave.net
Quote Reply
Re: How to display time? In reply to
Yeah I think so.

------------------
Patrick Chukwura
Nytesoft WebSolutions
nytesoft.hypermart.net
Quote Reply
Re: How to display time? In reply to
Try something like this - nice and short...

Quote:
if ($hour > 12) {
$hour = $hour - 12;
$ampm = " <small>P.M.</small>";
} else {
$ampm = " <small>A.M.</small>";
}

Then stick $ampm where needed.

------------------
Charles Capps
http://solareclipse.net/
Quote Reply
Re: How to display time? In reply to
OK, thanx that is easier.

------------------
Patrick Chukwura
Nytesoft WebSolutions
nytesoft.hypermart.net
Quote Reply
Re: How to display time? In reply to
How do you get the date and time when an end-user accesses a script? I would like to put a time/date stamp in my search script that logs when the person accesses the script.

Any suggestions???

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: How to display time? In reply to
I made a script that displays the time but I dont know how to do what your talking about.

------------------
Patrick Chukwura
Nytesoft WebSolutions
nytesoft.hypermart.net
Quote Reply
Re: How to display time? In reply to
Pasha,

That may serve as a decent starting point. However, I need to have the results sent to a log file along with the other variables within the search script. I will test it to see if it works (as a sub-routine).

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: How to display time? In reply to
niteridarz,

Here's a little upgrade to your Nytedate script:

Code:
if ($Choice eq "1")
{
$display = "<b>$day: $month/$date/$year</b>";
}
elsif ($Choice eq "2")
{
$display = "<i>$month/$date/$year-$day</i>";
}
elsif ($Choice eq "3")
{
$display = "<b><font color=\"$color\">$day: $month/$date/$year</font></b>>";
}
open (DAT,">time.dat");
print DAT "$display\n";
close(DAT);
print "$display";

this will print the time and date as it was before, and it will print the same to the database, new entry to the each new line.


Eliot,

niteridarz's script actually writes the time and date of an execution of the script. Take a look at it: http://nytesoft.hypermart.net/Perl/

Regards,

Pasha

------------------
webmaster@find.virtualave.net
http://find.virtualave.net
Quote Reply
Re: How to display time? In reply to
Thanx Pasha,
do you know how to answer this question?
http://www.gossamer-threads.com/...um8/HTML/000503.html

------------------
Patrick Chukwura
Nytesoft WebSolutions
nytesoft.hypermart.net
Quote Reply
Re: How to display time? In reply to
I am looking for a sub-routine that can be placed in a search script that logs the date and time when end users access the search form.

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: How to display time? In reply to
niteridarz,

I have already wrote a script similar to what you were asking:
Simple Database
http://find.virtualave.net/00/

The only thing you need to modify is the HTML output.

P.S. post reply here, if you need help Smile

Regards,

Pasha


------------------
webmaster@find.virtualave.net
http://find.virtualave.net
Quote Reply
Re: How to display time? In reply to
Pasha, you have some real handy scripts there!

------------------
Patrick Chukwura
Nytesoft WebSolutions
nytesoft.hypermart.net
Quote Reply
Re: How to display time? In reply to
Feel free to use 'em Smile
Quote Reply
Re: How to display time? In reply to
Pasha, about that database script on your site...
You have an array called '@entries'. How do I make the entries array stand for what a user submitted in a form?( how would I make the entries as an array, then split them into lines in a log or txt file)? Like a guestbook I created.

------------------
Patrick Chukwura
Nytesoft WebSolutions
nytesoft.hypermart.net
Quote Reply
Re: How to display time? In reply to
I found a quick and dirty way to insert the date and time in a log file:

print SUMMARY "<$font><b>Time and Date Visited:</b>\t", scalar localtime(time), "\n";

Thanks for all your helpful suggestions.

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: How to display time? In reply to
lol no prob,
-------------------------------------------

Does anyone know how a script or a simple code will look if I wanted to make a random image viewer?

------------------
Patrick Chukwura
Nytesoft WebSolutions
nytesoft.hypermart.net
Quote Reply
Re: How to display time? In reply to
Sorry dude, I don't give support for my scripts Smile

Random image viewer?
This is what I made to display ads on my site:

Code:
#!/usr/bin/perl
# <!--#exec cgi="/cgi-bin/ads.cgi" -->

open (FILE, "</home/find/private/ads.dat");
@LINES=<FILE>;
close(FILE);
srand;

print "Content-type: text/html\n\n$LINES[int rand(@LINES)]\n";

The database looks like this:

Code:
<A HREF="http://www.eads.com/adserve/adserve.dll/link?GB03747,0,0"><IMG BORDER=0 SRC="http://www.eads.com/adserve/adserve.dll/banner?GB03747,0,0" HEIGHT=55 WIDTH=460 ALT="Click Here to Visit Our Sponsor"></A>
<A HREF="http://www.eads.com/adserve/adserve.dll/link?GB03747,0,1"><IMG BORDER=0 SRC="http://www.eads.com/adserve/adserve.dll/banner?GB03747,0,1" HEIGHT=55 WIDTH=460 ALT="Click Here to Visit Our Sponsor"></A>
<A HREF="http://www.eads.com/adserve/adserve.dll/link?GB03747,0,2"><IMG BORDER=0 SRC="http://www.eads.com/adserve/adserve.dll/banner?GB03747,0,2" HEIGHT=55 WIDTH=460 ALT="Click Here to Visit Our Sponsor"></A>
<A HREF="http://www.eads.com/adserve/adserve.dll/link?GB03747,0,3"><IMG BORDER=0 SRC="http://www.eads.com/adserve/adserve.dll/banner?GB03747,0,3" HEIGHT=55 WIDTH=460 ALT="Click Here to Visit Our Sponsor"></A>
<A HREF="http://www.eads.com/adserve/adserve.dll/link?GB03747,0,4"><IMG BORDER=0 SRC="http://www.eads.com/adserve/adserve.dll/banner?GB03747,0,4" HEIGHT=55 WIDTH=460 ALT="Click Here to Visit Our Sponsor"></A>

Pretty simple, huh? Smile

Regards,

Pasha

------------------
webmaster@find.virtualave.net
http://find.virtualave.net
Quote Reply
Re: How to display time? In reply to
You can also try the following script:

Random Image Displayer
http://www.technotrade.com

It does NOT require SSI. In addition, there are some really nice ASP scripts that you can use for randomly displaying images.

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: How to display time? In reply to
Pasha, but I want it so someone can submit it through a form and it adds it, instead of having to constantly editing the CGI script.

Eliot, nah, I want to make my own.(with some help, lol)

Quote:
This thread is getting pretty big heh

------------------
Patrick Chukwura
Nytesoft WebSolutions
nytesoft.hypermart.net
Quote Reply
Re: How to display time? In reply to
This will submit the ads to the database:

Code:
#!/usr/bin/perl

$html = qq~
Thank you for submitting your Ads!
~;

print "Content-Type: text/html\n\n";

use CGI;
$in = new CGI;
$URL = $in->param('URL');
$Alt = $in->param('Alt');
$Image = $in->param('Image');

open (ADS,">>/home/find/private/test/ads.dat");
print ADS "<a href=\"$URL\"><img alt=\"$Alt\" border=0 src=\"$Image\"></a>\n";
close(ADS);
print "$html";

You just have to make an HTML form Smile

Regards,

Pasha

------------------
webmaster@find.virtualave.net
http://find.virtualave.net
Quote Reply
Re: How to display time? In reply to
sorry if I'm bothering you Pasha,
but where would the form send to? Will it be in the same file as the code you did above?

------------------
Patrick Chukwura
Nytesoft WebSolutions
nytesoft.hypermart.net
Quote Reply
Re: How to display time? In reply to
This form should be sent to this CGI script (just name the script whatever you want).

The form has only three fields:
URL
Alt
Image

Good luck!

Pasha

------------------
Something like this:

Code:
/cgi-bin/script.cgi?URL=www.yahoo.com&Alt=Yahoo&Image=www.yahoo.com/yahoo.gif

Good luck!

Pasha

[This message has been edited by Pasha (edited July 07, 1999).]