开发者

Undefined subroutine &main::timelocal error

I have the following error when 开发者_JAVA技巧I execute my perl module :

Undefined subroutine &main::timelocal

I have defined time and I want in the format of DDMMYYYY without any seperators.

Can anyone help me on this?


To use timelocal like that, you need to import it:

use Time::Local 'timelocal';

(and make sure you are calling it correctly; see Time::Local)

But perhaps you meant localtime? Or you might want POSIX::strftime.


You was not very specific where to get the time. This works for current date, using core Time::Piece module:

use Time::Piece;
print localtime->dmy('');    # 05042011

If you have time in variable, you can do

use Time::Piece;
print localtime($time)->dmy('');

The empty string in dmy call is separator.


The core POSIX module contains a 'strftime' function that handles all of the standard Unix date/time formatting sequences.

$ perl -MPOSIX=strftime -le'print strftime "%d%m%Y", localtime'

Or, in a program,

use POSIX 'strftime';

print strftime '%d%m%Y', localtime, "\n";


It's an old one but I had this exact error and solved it from looking at the above examples with a different solution.

Reason was that I had not included the ';' at the end of the use statement!

use Time::Local ;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜