gpt4 book ai didi

c# - 配置中的天数时间跨度?

转载 作者:可可西里 更新时间:2023-11-01 02:59:23 24 4
gpt4 key购买 nike

TimeSpanConfigurationElement 似乎无法处理大于 23:59:59 的值。有什么解决方法吗?继承 TimeSpan 并创建一个新的 TimeSpanValidatorAttribute 是否可行?我需要处理从几分钟到几天的时间跨度。

我正在使用以下配置部分

[ConfigurationProperty("SequenceRolloverDOSCompare", IsRequired = true)]
[TimeSpanValidator(MinValueString = "0:0:00", MaxValueString = 10675199.02:48:05.4775807", ExcludeRange = false)]
public TimeSpan SequenceRolloverDOSCompare
{
get
{
return (TimeSpan)base["SequenceRolloverDOSCompare"];
}
}

配置如下:

<SequenceRolloverPolling SequenceRolloverDOSCompare="2:00:00:00"  />

给出 ConfigurationErrorsException:无法解析属性“SequenceRolloverDOSCompare”的值。错误是:2:00:00:00 不是 TimeSpan 的有效值。

或者这个:

<SequenceRolloverPolling SequenceRolloverDOSCompare="48:00:00"  />

给出 OverflowException:无法解析 TimeSpan,因为小时、分钟或秒组件中至少有一个超出了其有效范围

最佳答案

在天和小时之间使用 . 分隔符:

<SequenceRolloverPolling
SequenceRolloverDOSCompare="2.00:00:00" />

TimeSpan format定义为:

... [-]d.hh:mm:ss.ff, where the optional minus sign indicates a negative time interval, the d component is days, hh is hours as measured on a 24-hour clock, mm is minutes, ss is seconds, and ff is fractions of a second.

关于c# - 配置中的天数时间跨度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3145691/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com