[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] time functions with MacPerl 5.1.3.r2



In message "[MacPerl] time functions with MacPerl 5.1.3.r2", David Beck wrote:
>I have read the several recent postings about the time formatting functions
>in timelocal.pl (warned not to use!) and Time::Local. However, I can't even
>do something as simple as getting the current system time, forget
>formatting.

My favorite method is as follows:

&get_date;
print $date;

sub get_date {

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

	#get day name
	$day_name =
('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday')[$wday];

	#get month name
	$month_name =
('January','February','March','April','May','June','July',
          'August','September','October','November','December')[$mon];

	#determine AM or PM so we can use 12 hour clock
	if ($hour > 11) {
		$ampm='PM';
	}
	else {
		$ampm='AM';
	}

	#convert to 12 hour clock
	if ($hour > 12) {
		$hour -= 12;
	}

	if ($hour == 0) {
 		$hour = 12;
	}

	#add 0 where needed to minutes and seconds
	if ($min < 10) {
		$min = "0$min";
	}

	if ($sec < 10) {
		$sec = "0$sec";
	}


	$date = "$day_name, $month_name $mday, 19$year at $hour\:$min\:$sec
$ampm";

}

___________________________________________________________
David Turley
dturley@illuminet.net
Fredericksburg, VA
USA

"If you want to know what God thinks about money, just
     look at the people He gives it to."
                                     -- Old Irish Saying

___________________________________________________________




***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch