如何使用Perl进行日期时间比较和计算三角洲? [英] How can I use Perl to do datetime comparisons and calculate deltas?

查看:157
本文介绍了如何使用Perl进行日期时间比较和计算三角洲?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从人类可读的文本中提取了年,月,日,时,分,秒和毫秒的数据(它不是时间戳格式,而是像在HH:MM:SS.SSS on DD MMM YYYY并以HH:MM:SS.SSSS在DD MMM YYYY结束),因此对于每个记录的事件,我都有每个值。



然而,我需要把它们变成某种时间戳,所以我可以做数学 - 我想确定事件持续多久(结束时间 - 开始时间)。我希望时间函数将参数,所以我可以创建两个任意的时间,但不会出现如果可能,我想要坚持使用可以添加到项目的核心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 times, 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屋!

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