Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Perl Beginners Cgi > Re: Adding a co...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 6 of 6 Topic 1386 of 1496
Post > Topic >>

Re: Adding a comma to format localtime

by Peter@[EMAIL PROTECTED] (Peter Scott) Apr 12, 2007 at 06:54 AM

On Thu, 12 Apr 2007 05:56:14 -0500, Paul Archer wrote:
> A cleaner way to do it is:
> printf "%s, %s %s %s %s\n", (split ' ', localtime)[0,2,1,4,3];
> Or, if you want to save it to a variable:
> my $dateout = sprintf "%s, %s %s %s %s\n", (split ' ',
localtime)[0,2,1,4,3];
>>
>> On 4/9/07, Gregg O'Donnell <gpod363@[EMAIL PROTECTED]
> wrote:
>>> All,
>>>   I use this line of code:
>>>   my $datetime = join ' ', (split ' ', localtime)[0,2,1,4,3];
>>> 
>>>   To create this result:
>>>   Mon 9 Apr 2007 09:15:05
>>> 
>>>   How can I add a comma to this result to get:
>>>   Mon, 9 Apr 2007 09:15:05

Personally, I find this more maintainable and readable:

use POSIX qw(strftime);
my $datetime = strftime "%a, %d %b %Y %T", localtime;

-- 
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/
 




 6 Posts in Topic:
Adding a comma to format localtime
gpod363@[EMAIL PROTECTED]  2007-04-09 09:41:57 
Re: Adding a comma to format localtime
wiggins@[EMAIL PROTECTED]  2007-04-09 11:11:52 
Re: Adding a comma to format localtime
krahnj@[EMAIL PROTECTED]   2007-04-11 09:35:52 
Re: Adding a comma to format localtime
susheelm@[EMAIL PROTECTED  2007-04-12 11:57:39 
Re: Adding a comma to format localtime
tigger@[EMAIL PROTECTED]   2007-04-12 05:56:14 
Re: Adding a comma to format localtime
Peter@[EMAIL PROTECTED]   2007-04-12 06:54:40 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Nov 22 10:36:03 CST 2008.