【问题标题】:perl datetime output explainperl datetime 输出解释
【发布时间】:2013-01-28 15:41:11
【问题描述】:

perl 代码:

#!/bin/env perl

use DateTime;

print DateTime->now;

输出:

2013-01-28T06:02:33

输出字符串中的“T”字母是什么意思?

【问题讨论】:

    标签: perl datetime


    【解决方案1】:

    ISO8601 和 RFC3339 都使用“T”来连接日期和时间,而 DateTime 的默认字符串化符显然采用了该约定。如果您想要其他格式,可以使用 DateTime::Format::* 模块或->strftime

    my $now = DateTime->now( time_zone => 'local' );
    say $now->strftime('%Y-%m-%d %H:%M:%S');
    

    【讨论】:

      【解决方案2】:

      它代表“时间”。你可以阅读更多:

      http://en.wikipedia.org/wiki/ISO_8601#Combined_date_and_time_representations

      【讨论】:

        【解决方案3】:

        它是ISO 8601 中日期和时间的分隔符。这种格式总是一个 T。

        【讨论】:

          【解决方案4】:

          字符 [T] 应用作时间指示符,以指示一天中时间表示的开始 这些表达式中的组成部分。根据 4.4.4,应使用连字符 [-] 和冒号 [:],如 需要时,分别在日期和时间表达式中的分隔符。

          注意 经信息交换合作方协商一致,[T]字符可省略 不存在将日期和时间表示与本文中定义的其他表示混淆的风险的应用 国际标准。

          --Data elements and interchange formats — Information interchange — Representation of dates and times, ISO 8601:2004(E)

          【讨论】:

            猜你喜欢
            • 2016-05-13
            • 2023-03-18
            • 2012-05-19
            • 2014-02-17
            • 2011-05-03
            • 2012-02-17
            • 2021-12-18
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多