使用NodaTime解析DateTime字符串 [英] Parsing DateTime string using NodaTime

查看:59
本文介绍了使用NodaTime解析DateTime字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  var模式= LocalDateTimePattern.CreateWithInvariantCulture(dateTimePattern);var parseResult = pattern.Parse(dateTimeString);如果(!parseResult.Success){//引发异常或您想执行的任何操作} 

当我查看野田时间API .但是,我无法使用它.我错过了什么吗?

解决方案

您没有说您正在使用哪个版本的Noda Time,但我怀疑它是1.1.0(即最新发布的版本)./p>

ZonedDateTimePattern 仅在Noda Time的开发版本中可用(发行时将变为1.2.0);如路线图所述,1.2.0将包括更好的文本处理,包括对 ZonedDateTime OffsetDateTime .

恐怕在1.1.x中无法直接解析 ZonedDateTime (如 Noda Time API. But, I am not able to use it. Am I missing out something?

解决方案

You don't say which version of Noda Time you're using, but I suspect it's 1.1.0 (that is, the latest released version).

ZonedDateTimePattern is only available in the development version of Noda Time (which will become 1.2.0 when it's released); as mentioned in the roadmap, 1.2.0 will include better text handling, including parsing for ZonedDateTime and OffsetDateTime.

I'm afraid that in 1.1.x there's no way to parse a ZonedDateTime directly (as noted in the limitations section of the 1.1.x user guide), though you could parse an Instant and a timezone name separately, and construct a ZonedDateTime by hand.

这篇关于使用NodaTime解析DateTime字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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