如何验证“ yyyy-MM-dd'T'HH:mm:ssZ” Perl在UTC中显示日期/时间戳? [英] How can I validate a "yyyy-MM-dd'T'HH:mm:ssZ" date/timestamp in UTC with Perl?

查看:86
本文介绍了如何验证“ yyyy-MM-dd'T'HH:mm:ssZ” Perl在UTC中显示日期/时间戳?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码会很好,但正确方向的一点也很好。

Code would be nice but a point in the right direction is good as well.

CPAN吗?正则表达式?

CPAN? RegEx?

我已经看过两种方式

yyyy-MM-dd'T'HH:mm :ssZ;

"yyyy-MM-dd'T'HH:mm:ssZ";

yyyy-MM-ddTHH:mm:ssZ;

"yyyy-MM-ddTHH:mm:ssZ";

推荐答案

以太,日期时间肯定在正确的轨道上。使用DateTime,可以确保您确实有一个时间,如果您自己编写支票,可能会在2000年2月29日得到解决。

Ether is definitely on the right track with DateTime. Using DateTime, you can be sure that you have a time that actually exists, where something on Feb 29, 2000 might get by if you wrote the checks yourself.

您的格式看起来像一个ISO8601字符串。因此,请使用 DateTime :: Format :: ISO8601 进行解析。

Your format looks like an ISO8601 string. So, use DateTime::Format::ISO8601 to do your parsing.

use DateTime;
use DateTime::Format::ISO8601;

my $string = '2010-02-28T15:21:33Z';

my $dt = DateTime::Format::ISO8601->parse_datetime( $string );
die "Impossible time" unless $dt;

您可以使用其他格式模块,例如 D :: F :: Strptime ,但是您最终将重新创建ISO8601格式化程序会。

You could use other format modules, such as D::F::Strptime, but you will wind up recreating what ISO8601 formatter already does.

这篇关于如何验证“ yyyy-MM-dd'T'HH:mm:ssZ” Perl在UTC中显示日期/时间戳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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