in reply to Question on date formatting
The re-ordering of the first three fields depends on whether the field separators are periods or slashes, and the sprintf for the output format makes sure to include leading zeroes when necessary.s{ (\d{1,2}) ([./]) (\d{1,2}) \2 (\d{4}) \s+ (\d{1,2}):(\d{2}) } { my @a=($2 eq ".") ? ($4,$3,$1) : ($4,$1,$3); sprintf( "%s-%02d-%02d %02d:%s", @a,$5,$6 ) }ex;
(updated to try improving legibility of the code -- not sure I succeeded)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Question on date formatting
by KarthikK (Sexton) on Jun 20, 2008 at 08:21 UTC | |
by graff (Chancellor) on Jun 20, 2008 at 14:30 UTC |