2013-05-30 72 views
0

如何使用NodaTime解析Zoned DateTime字符串?我目前使用LocalDateTimePattern进行解析,但我认为DateTime的值取决于服务器的时区。使用NodaTime解析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。但是,我无法使用它。我错过了什么吗?

回答

1

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

ZonedDateTimePattern仅适用于Noda Time的开发版本(它在发布时会变为1.2.0);如the roadmap中所述,1.2.0将包括更好的文本处理,包括解析ZonedDateTimeOffsetDateTime

恐怕在1.1.x版本有没有办法直接解析ZonedDateTime(如1.1.x版本用户指南的limitations部分说明),但你可以单独解析Instant和时区的名称,手动构建ZonedDateTime