2013-11-01 14 views
1

我想使用now()函數在perl中顯示當前日期和時間。我使用Active Perl軟件運行此腳本,但出現錯誤。現在用於顯示不通過ActivePerl工作的日期和時間

#! /usr/bin/perl 
use Date::Parse; 
$date = str2time(now()); 
print "$date\n"; 

我得到的錯誤爲:

C:\Users\admin\Desktop>perl test.pl 
Can't locate Date/Parse.pm in @INC (@INC contains: C:/Perl/site/lib C:/Perl/lib 
.) at test.pl line 3. 
BEGIN failed--compilation aborted at test.pl line 3. 

請幫助。

+0

如果你想要當前的Unix時間,爲什麼不使用['time'](http://perldoc.perl.org/functions/time.html「perldoc -f time」)? –

回答

6

您沒有在ActivePerl中默認安裝模塊Date::Parse

你可以解決這個問題:

ppm install Date::Parse 

這工作對我來說是ActivePerl 5.16默認安裝。

+0

安裝模塊後,我得到C:\ Users \ admin \ Desktop> perl test.pl 未定義的子程序和main ::現在在test.pl第3行調用。 – user1613245

+2

嘗試使用'localtime()'或'gmtime()'現在()' – mvp

+0

謝謝。 localtime()和gmtime()都起作用。 – user1613245