是否需要 Date、Time 和 DateTime 类? [英] Are the Date, Time, and DateTime classes necessary?
问题描述
当有一个可以同时处理 Date
和 Time
的类时,拥有 Date
和 Time
类的目的是什么?
What is the purpose of having Date
and Time
classes when there is a DateTime
class that can handle both?
推荐答案
DateTime
是 Date
的子类,所以你可以用 Date
可以用 DateTime
来完成.但正如 tadman 和 steenslag 指出的那样,DateTime
较慢.请参阅 steenslag 的答案,了解它有多慢.
DateTime
is a subclass of Date
, so whatever you can do with Date
can be done with DateTime
. But as tadman and steenslag point out, DateTime
is slower. See steenslag's answer for how much slower it is.
关于DateTime
与Time
,我发现了一些这里.
With respect to DateTime
vs, Time
, I found something here.
引用
Time is a wrapper around Unix-Epoch.
Date (and DateTime) use rational and a "day zero" for storage. So Time
is faster but the upper and lower bounds are tied to epoch time (which
for 32bit epoch times is something around 1970-2040 ... while Date (and DateTime) have an
almost infinite range but are terribly slow.
<小时>
简而言之,DateTime
是一个全能的超级明星,一般来说应该是首选,但如果你想优化到最后一点,使用Time
可以提高性能.
In short, DateTime
is an all around superstar, and should be preferred in general, but if you want to optimize to the last bit, using Time
can improve performance.
这篇关于是否需要 Date、Time 和 DateTime 类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!