sub nice_date { (my $date) = @_; ($sec, $min, $hr, $day, $month, $year, $day_Of_Week, $julianDate, $dst) = localtime($date); $month+=1; $year+=1900; ($sec2, $min2, $hr2, $day2, $month2, $year2, $day_Of_Week2, $julianDate2, $dst2) = localtime(); $month2+=1; $year2+=1900; if($julianDate2==$julianDate and $year==$year2) { if($hr==$hr2) {print "a few moments ago";} elsif(($hr2-$hr)==1) {print "an hour ago";} elsif(($hr2-$hr)==2) {print "two hours ago}";} elsif(($hr2-$hr)==3) {print "three hours ago";} else {print "today";} } elsif($julianDate2==($julianDate+1) and $year==$year2) {print "yesterday";} elsif(($julianDate2-$julianDate)<=2 and $year==$year2) {print "two days ago";} elsif(($julianDate2-$julianDate)<=5 and $year==$year2) {print "this week";} else {print "$month/$day/$year";} }
Never been to CodeSnippets before?
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)
Nice Date (See related posts)
You need to create an account or log in to post comments to this site.
Related Posts
» Measure the daily number of ... in email date perl shell bash mime day mailbox
» How to setup NTP on BSD in ntpdate ntpd ntp.conf time date
» Encode and Decode strings fr... in perl regex
» Parse comma separated data in perl regex
» Improved user_box for Scoop in perl scoop
» Improved admin_tools for Scoop in perl scoop
Snippets (source code soon to be available) developed by Peter Cooper and powered by Ruby On Rails