Are the Date, Time, and DateTime classes necessary?

前端 未结 5 1622
生来不讨喜
生来不讨喜 2020-12-08 00:51

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

5条回答
  •  既然无缘
    2020-12-08 01:05

    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.

    With respect to DateTime vs, Time, I found something here.

    Citation


    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.
    

    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.

提交回复
热议问题