如何将 dd/MMM/yy hh:mm AM/PM 转换为 iCal 事件格式?

发布于 2024-12-29 01:31:42 字数 183 浏览 1 评论 0原文

我有一个采用以下格式的日期时间列表:

05/Jan/12 8:00 AM

日期始终为两位数,但小时可以为一位数或两位数。

我想将其转换为 iCal 格式:

20120105T080000Z

是否有模块可以执行此操作?

I have a list of date-times in this format:

05/Jan/12 8:00 AM

The day is always two digits, but the hour can be either one or two digits.

I'd like to convert that to iCal format:

20120105T080000Z

Is there a module that does this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

辞慾 2025-01-05 01:31:42

Time::Piece 核心模块就足够了:

#!/usr/bin/env perl
use strict;
use warnings;
use Time::Piece;
my $str = q(05/Jan/12 8:00 AM);
my $t = Time::Piece->strptime($str,"%d/%b/%y %I:%M %p");
print $t->datetime, "\n";

这假设您的当地时间,并将在输出中包含破折号:

2012-01-05T08:00:00

The Time::Piece core module would suffice:

#!/usr/bin/env perl
use strict;
use warnings;
use Time::Piece;
my $str = q(05/Jan/12 8:00 AM);
my $t = Time::Piece->strptime($str,"%d/%b/%y %I:%M %p");
print $t->datetime, "\n";

This assumes your localtime and would include dashes in the output:

2012-01-05T08:00:00
风吹短裙飘 2025-01-05 01:31:42

应该能够使用 DateTime::Format::Strptime 和 日期时间::格式::ICal

此外,您的输出似乎采用 UTC/GMT(由尾随“Z”表示),但您的输入未指定时区。因此,作为解决方案的一部分,您需要指定应解释输入时间的时区。

另请参阅 http://datetime.perl.org/wiki/datetime/page/Modules

Should be able to do it using a combination of DateTime::Format::Strptime and DateTime::Format::ICal.

Also, your output appears to be in UTC/GMT (indicated by the trailing 'Z'), but your input doesn't specify a timezone. So as part of your solution you will need to specify what time zone the input times should be interpreted in.

See also http://datetime.perl.org/wiki/datetime/page/Modules

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文