如何在 Perl 中给定 GMT/UTC 偏移量的时区计算本地时间?
我需要找出给定地点的当地时间。我有该位置的 GMT/UTC 偏移量。我试图通过获取该时区中设置的截止日期之间的差异来获取持续时间,以在该特定时区中达到截止日期时触发发送电子邮件。
例如,如果西雅图的截止日期设置为 2011 年 9 月 10 日 12:00:00 GMT -7:00,如果我现在在英国,我需要计算西雅图现在的时间,给定 GMT 偏移量 -7:00 一旦我得到我可以计算差异,如果差异为 0,那么我会发送一封电子邮件,说明截止日期已到。
我如何在 Perl 中进行时间计算部分?
请帮忙。
谢谢, 苏尼尔
I need to find out what is local time at a given location. I have GMT/UTC offset for that location. I am trying to get a time duration by taking a difference between deadline set in that time zone to trigger emails being sent out when deadline is met in that perticular time zone.
Ex.If deadline is set in Seattle to be Sept 10, 2011 12:00:00 GMT -7:00 now if I am in UK I need to calculate what time is now in Seattle given GMT offset -7:00 once I get that I can calculate the difference if the difference is 0 then I will sent out an email saying deadline is met.
How can I do the time calculation part in Perl?
Please help.
Thanks,
Sunyl
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
创建一个 DateTime 对象,并将其与
DateTime->now
进行比较。 DateTime 对象知道与其中的时间戳关联的时区,因此它可以毫不费力地执行您想要的操作。上面,我假设您复制了日期格式。如果日期按照您提供的格式设置,您将无法使用 Strptime,因为时间戳使用非标准的月份名称和非标准的偏移量格式。
Create a DateTime object, and compare it to
DateTime->now
. The DateTime object is aware of the time zone associated with the timestamp therein, so it can do what you want with no fuss.Above, I assumed you miscopied the date format. If the date is formatted as you provided, you won't be able to use Strptime because the timestamp uses nonstandard names for the months and a nonstandard format for the offset.
您可以使用 CPAN 中的 DateTime 模块进行时间计算。
http://metacpan.org/pod/DateTime
它还有您可以利用的时区信息。应该非常简单,因为文档非常清楚。
具体来说,
希望有帮助!
编辑:
这也可能很重要/会让生活更轻松,
You can use the DateTime module from CPAN to do time calculations.
http://metacpan.org/pod/DateTime
It's got time zone stuff that you can leverage as well. Should be pretty straight forward as the documentation is pretty clear.
Specifically,
Hope that helps!
Edit:
Also this is probably important/will make life easier,