带有小时,分钟和秒的时间段 [英] Period with hours, minutes and seconds
问题描述
我需要一个表示年,月,周,天,小时,分钟,秒的间隔数据类型.前三个(年,月,日)可以使用Period
完成,后三个(小时,分钟,秒)可以使用Duration
完成,但是似乎两者都不能执行.理想情况下,我希望避免实施自定义TemporalAmount
.
I have need for an interval data type representing years, months, weeks, days, hours, minutes, seconds. The first three (years, months, days) can be done with Period
and the last three (hours, minutes, seconds) can be done with Duration
however none of them seem to do both. Ideally I'd like to avoid having to implement a custom TemporalAmount
.
推荐答案
没有这种类型的原因.没有明确定义的时间间隔,例如天",月"或年":
There is a reason why there is no such type. There is no well defined time intervals such as "day", "month" or "year":
- 一天并非总是24小时(取决于DST,时区和leap秒)
- 每个月的天数不同
- le年有366天
即使您实现了自定义的TemporalAmount,在某些情况下您的代码也极有可能是错误的.如果您陈述自己的实际要求,则可能会得到更好的答案.
Even if you implement a custom TemporalAmount there is high chance that your code will be incorrect in some cases. If you state your actual requirements you might get a better answer.
这篇关于带有小时,分钟和秒的时间段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!