Reply to topic
perl date and time
mesum98


Joined: 27 Oct 2005
Posts: 5
Reply with quote
I just want to know how to output the date and time in perl in following format
03:58 10/27/2005

Also if I wish to increment the time by 2 hours

could anyone please help

thanks

m
bobclingan
Forum Regular

Joined: 16 Sep 2004
Posts: 271
Location: Abingdon, MD
Reply with quote
Did you look on CPAN? They have a nice module for formatting dates and times:

http://search.cpan.org/~rse/lcwa-1.0.0/lib/timedate/Date/Format.pm

You might also find this site useful:

http://datetime.perl.org/faq.html
Can't locate DateTime.pm
mesum98


Joined: 27 Oct 2005
Posts: 5
Reply with quote
Thanks, but I my webhost seems not to recognize the libraries

In summary my webserver supports the following modules
http://j2se.co.uk/server_info/servercheck.pl?compile&7

so any advice or simple script using available modules ??

Thanks in advance
bobclingan
Forum Regular

Joined: 16 Sep 2004
Posts: 271
Location: Abingdon, MD
Reply with quote
Date format is in that list
mesum98


Joined: 27 Oct 2005
Posts: 5
Reply with quote
My script is as bellow
#!/usr/bin/perl

use Mysql;
use CGI qw(:standard);
my @row;
use Date::Format;


print "content-type: text/html\n\n";
print "<HTML><HEAD><TITLE></TITLE></HEAD>";
print "<BODY>";
@lt = timelocal(time);
print time2str($template, time);
print strftime($template, @lt);

print time2str($template, time, $zone);
print strftime($template, @lt, $zone);

print ctime(time);
print ascctime(@lt);

print ctime(time, $zone);
print asctime(@lt, $zone);

print "</BODY></HTML>\n";

exit;

But this does not have any output
can you please put me in the correct direction
@lt = timelocal(time);
mesum98


Joined: 27 Oct 2005
Posts: 5
Reply with quote
I deleted @lt = timelocal(time); and it gave me the date output#Thanks
03:58 10/27/2005
mesum98


Joined: 27 Oct 2005
Posts: 5
Reply with quote
Stuck again

can you help?
Just want to format the date in the following order
03:58 10/27/2005
babarrett


Joined: 04 Jun 2006
Posts: 1
Reply with quote
There are, of course, many ways to do this. This is one that works, feel free to improve on it.
Hope it helps.

#!/usr/bin/perl

use HTTP::Date;
my ($date, $time) = split(" ", HTTP::Date::time2iso());
my ($hour, $min) = split(":", $time);
print "$hour:$min $date\n\n";
exit;
spoulson


Joined: 21 Jun 2006
Posts: 22
Location: Middletown, DE
Reply with quote
Love it or hate it:
Code:
my $datestring = prettydate();
print $datestring;

# usage: $string = prettydate( [$time_t] );
# omit parameter for current time/date
sub prettydate {
   @_ = localtime(shift || time);
   return(sprintf("%02d:%02d %02d/%02d/%04d", @_[2,1], $_[4]+1, $_[3], $_[5]+1900));
}
perl date and time
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT  
Page 1 of 1  

  
  
 Reply to topic