【问题标题】:Parsing DateTime string using NodaTime使用 NodaTime 解析 DateTime 字符串
【发布时间】:2013-05-30 06:33:41
【问题描述】:

我们如何使用 NodaTime 解析 Zoned DateTime 字符串?我目前正在使用 LocalDateTimePattern 进行解析,但我认为生成的 DateTime 值将在 服务器的时区中。

var pattern = LocalDateTimePattern.CreateWithInvariantCulture(dateTimePattern);

var parseResult = pattern.Parse(dateTimeString);
if (!parseResult.Success)
{
   // throw an exception or whatever you want to do
}

我在查看 ZonedDateTime 模式时遇到了 Noda Time API。但是,我无法使用它。我错过了什么吗?

【问题讨论】:

    标签: datetime nodatime


    【解决方案1】:

    你没有说你使用的是哪个版本的 Noda Time,但我怀疑它是 1.1.0(即最新发布的版本)。

    ZonedDateTimePattern仅在野田时代的开发版中可用(发布后将变为1.2.0);正如the roadmap 中提到的,1.2.0 将包括更好的文本处理,包括解析ZonedDateTimeOffsetDateTime

    恐怕在 1.1.x 中无法直接解析 ZonedDateTime(如 1.1.x 用户指南的 limitations 部分所述),尽管您可以解析 Instant 和时区名称分开,并手动构造一个ZonedDateTime

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-07
      • 2011-11-26
      • 2020-09-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多