【问题标题】:Why does DateTime add a T separator to the timestamp?为什么 DateTime 会在时间戳中添加 T 分隔符?
【发布时间】:2012-08-17 20:22:19
【问题描述】:

我的代码:

print DateTime->now;

回复:

2012-08-17T20:16:37

为什么会有 T?有没有我忘记的选项?

【问题讨论】:

    标签: perl datetime


    【解决方案1】:

    T 只是一种标准 (ISO 8601) 方式来分隔时间。要使用其他格式,请考虑使用strftimeformat_cldr

    例如,要使用空格,请使用DateTime->now->format_cldr("YYYY-MM-dd hh:mm:ss")

    【讨论】:

      【解决方案2】:

      字符串化DateTime 对象使用ISO 8601 格式,除非您在构造函数中指定了格式化程序。请参阅文档中的Formatters and Stringificationiso8601 方法是:

      sub iso8601 { join 'T', $_[0]->ymd('-'), $_[0]->hms(':') }
      

      【讨论】:

        【解决方案3】:

        这是DateTime 产生的默认输出格式,ISO-8601。如果你想要别的东西,你需要使用strftimeformat_cldr 方法或DateTime::Format::* 模块之一来输出不同的格式,例如:

        print DateTime->now->format_cldr("YYYY-MM-dd hh:mm:ss");
        

        【讨论】:

          【解决方案4】:

          这是日期和时间的 iso 标准,请参阅 http://en.wikipedia.org/wiki/ISO_8601

          参见例如How do you read the system time and date in Perl? 讨论以可格式化的方式读取日期/时间。

          【讨论】:

            猜你喜欢
            • 2016-01-27
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2016-12-16
            • 1970-01-01
            • 2021-10-27
            • 2019-07-02
            • 1970-01-01
            相关资源
            最近更新 更多