简体   繁体   English

如何使用Perl获取文件创建时间与当前时间的小时数差异

[英]How to i get the difference of time in hours for a file created time and the current time using perl

如何获取文件创建时间与当前时间(以小时为单位)之间的时差

stat($file)->mtime gives you the last modification time in seconds. stat($file)->mtime为您提供最后的修改时间,以秒为单位。 Subtract that from time and divide it by 3600 ... that should do the trick. time减去该值,然后除以3600 ...应该可以解决问题。

For calculations involving time or dates you can always rely on DateTime ! 对于涉及时间或日期的计算,您始终可以依靠DateTime

For your specific cuestion, you can use the constructor from_epoch to convert from Unix timestamp to DateTime. 对于您的特定提示,可以使用构造函数from_epoch从Unix时间戳转换为DateTime。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM