![]() |
Format Date/Time in Perl
Working with dates is a very common feature of any application, be it a web app or a desktop one. Some people consider Perl to be a language where working with dates is hard, but basically it's quite easy if you know how to. Datetime is a common term while refering to date and time together.
BasicsBasic formatting of datetime in Perl is done by writing your own formatting logic, we'll use the localtime function to get the current datetime details. For more info about the locatime function checkout http://perldoc.perl.org/functions/localtime.html Code: Perl
Enter POSIX::strftimeThe strftime function helps to format time information to string using pre-defined formatting parameters. Here's how we go about it, you might need a list of formatting string codes found at http://www.mkssoftware.com/docs/man3/strftime.3.asp Code: Perl
You can format the way you like it using the format parameters, I personally feel this is the easiest way to format datetime in Perl for daily use. Using Date::CalcThe Perl module Date::Calc's primary use is date manipulation, but it may also be used formatting dates to some extent, you may read the module's docs at http://search.cpan.org/~stbey/Date-Calc-5.4/Calc.pod Code: Perl
Hope this write-up was helpful. Happy coding. |
Re: Format Date/Time in Perl
Nice article....I have taken printout of it ...n will read @ home..
|
Re: Format Date/Time in Perl
Nice :D
|
Re: Format Date/Time in Perl
|
Re: Format Date/Time in Perl
Nice article.....
|
Re: Format Date/Time in Perl
Nice
|
Re: Format Date/Time in Perl
There is a bug in the code...
"$abbr[$mon] $mday"; Should be: "$month_abbr[$mon] $mday"; |
| All times are GMT +5.5. The time now is 16:33. |