C# DateTime: What “date” to use when I'm using just the “time”?

后端 未结 12 1636
陌清茗
陌清茗 2020-12-16 09:35

I\'m using a DateTime in C# to display times. What date portion does everyone use when constructing a time?

E.g. the following is not valid because ther

12条回答
  •  臣服心动
    2020-12-16 10:27

    May I suggest that in some cases a custom struct could do? It could have an Int32 backing value (there are 86 milion milliseconds in a day; this would fit in an Int32).

    There could be get-only properties :

    Hours Minutes Seconds Milliseconds

    You could also overload operators such as +, - and so on. Implement IEquatable, IComparable and whatever may be the case. Overload Equals, == . Overload and override ToString.

    You could also provide more methods to construct from a DateTime or append to a datetime and so on.

提交回复
热议问题