如何在Perl中将文件创建时间与当前时间进行比较? [英] How can I compare file creation time to the current time in Perl?

查看:218
本文介绍了如何在Perl中将文件创建时间与当前时间进行比较?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Perl中比较当前时间和文件创建时间,但是两者的格式不同.当地时间采用以下格式:

i want to compare the current time and file creation time in Perl but both are in different format. localtime is in this format:

22116291110813630

文件创建时间为

Today, December 29, 2008, 2:38:37 PM

我该如何比较哪个更大以及它们的不同?

How do i compare which one is greater and their difference?

推荐答案

比使用stat()和time()/localtime()更加容易.

It's even easier than using stat() and time()/localtime().

my $diff = -M $filename;

-M运算符返回文件的年龄"(自程序启动以来的天数).它记录在 -X函数perldoc -f -X中.

The -M operator returns the "age" of the file (in days since the start of the program). It's documented under the -X functions or in perldoc -f -X.

这篇关于如何在Perl中将文件创建时间与当前时间进行比较?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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