Are the Date, Time, and DateTime classes necessary?

前端 未结 5 1620
生来不讨喜
生来不讨喜 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:30

    Another way of thinking of this is that Date and DateTime model time in terms of clocks and calendars, which is useful for describing times to users, and scheduling events. Having a Date without a time is nice for when you don't care about the time, and you don't want to think about time zones.

    Time models time as a continuum, and is a wrapper around the Unix timestamp, which is just an integer. This is useful for all manner of internal applications where the computer doesn't care much whether a calendar boundary has been crossed, but just how many seconds (or milliseconds) have elapsed.

提交回复
热议问题