Date formatting
- From: "stagepin" <stagepin@xxxxxxxxx>
- Date: 30 Dec 2005 05:11:30 -0800
I am a Perl newbie and I would like to ask for some advice.
I need to manipulate the date format.
I receive $date in this format: yyyymmdd (For example: 20051230)
I need to display it as "December 30, 2005"
This is what I came up with to accomplish this task:
-----------------------------------------------------------------------------------------------
my @items = $date =~ m/(\d{4})(\d{2})(\d{2})/;
my $formatted_date = POSIX::strftime("%B %e, %Y",
localtime(timelocal(0,0,0,$items[2],$items[1]-1,$items[0])));
-----------------------------------------------------------------------------------------------
The above code is working just fine, but I am wondering if this is
actually a good way of doing this? Is there a more elegant way?
Any advice or comments would be appreciated!
Thank you
stagepin
.
- Follow-Ups:
- Re: Date formatting
- From: usenet
- Re: Date formatting
- Prev by Date: Working with very large text files
- Next by Date: Re: Working with very large text files
- Previous by thread: Working with very large text files
- Next by thread: Re: Date formatting
- Index(es):
Relevant Pages
|