如何在Perl中以DDMMYY格式获取文件修改日期? [英] How can I get a file's modification date in DDMMYY format in Perl?

查看:142
本文介绍了如何在Perl中以DDMMYY格式获取文件修改日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



(最初的问题是如何在没有DateTime的情况下执行此操作模块,我删除了这个限制,以使问题更加一般。)

解决方案

只有日期格式化我需要做,不需要任何日期功能,我只是使用POSIX(它附带Perl):

 使用POSIX; 

我的$ file =/ etc / passwd;

我的$ date = POSIX :: strftime(
%d%m%y,
localtime(
(stat $ file)[9]

);

忘记关于 -M t使用相对时间。直接进入 stat 以获取时代。


What's the best way to get a file's modification date in DDMMYY format in Perl?

(Originally the question was "How to do it without the DateTime module". I removed this restriction in order to make the question more general.)

解决方案

If this is the only date formatting I need to do and don't need any date features for anything else, I just use POSIX (which comes with Perl):

use POSIX;

my $file = "/etc/passwd";

my $date = POSIX::strftime( 
             "%d%m%y", 
             localtime( 
                 ( stat $file )[9]
                 )
             );

Forget about -M if you aren't using relative time. Go directly to stat to get the epoch time.

这篇关于如何在Perl中以DDMMYY格式获取文件修改日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆