带有小时,分钟和秒的时间段 [英] Period with hours, minutes and seconds

查看:110
本文介绍了带有小时,分钟和秒的时间段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个表示年,月,周,天,小时,分钟,秒的间隔数据类型.前三个(年,月,日)可以使用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屋!

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