是否需要 Date、Time 和 DateTime 类? [英] Are the Date, Time, and DateTime classes necessary?

查看:32
本文介绍了是否需要 Date、Time 和 DateTime 类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当有一个可以同时处理 DateTime 的类时,拥有 DateTime 类的目的是什么?

What is the purpose of having Date and Time classes when there is a DateTime class that can handle both?

推荐答案

DateTimeDate 的子类,所以你可以用 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.

关于DateTimeTime,我发现了一些这里.

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屋!

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