如何使用Perl进行日期时间比较和计算三角洲? [英] How can I use Perl to do datetime comparisons and calculate deltas?
问题描述
然而,我需要把它们变成某种时间戳,所以我可以做数学 - 我想确定事件持续多久(结束时间 - 开始时间)。我希望时间
函数将参数,所以我可以创建两个任意的时间
,但不会出现如果可能,我想要坚持使用可以添加到项目的核心Perl库或脚本中的功能,因为获取CPAN模块
p>您可以使用时间:本地来执行此操作。它基本上与内置的本地时间功能相反,因此您可以从标准日期生成时间戳。
I extracted year, month, day, hour, minute, second, and millisecond data from human readable text (it wasn't in a timestamp format, but rather something like "X started at HH:MM:SS.SSS on DD MMM YYYY and ended at HH:MM:SS.SSSS on DD MMM YYYY"), so for each recorded event, I have each of the values.
However, I need to turn those into some kind of timestamp so I can do math on it - I want to determine how long the event lasted (end time - start time). I was hoping the time
function would take parameters so I can create two arbitrary time
s, but that doesn't appear to be the case.
If possible, I would like to stick with functions available in the core Perl libraries or scripts that I can add to the project, since getting CPAN modules installed on the target machines would just make a headache for everyone, if it is even possible to get the modules through the security restrictions.
You can do it with Time:Local. It's basically the reverse of the built in "localtime" function, so you can generate a timestamp from a standard date.
这篇关于如何使用Perl进行日期时间比较和计算三角洲?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!