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

后端 未结 12 1639
陌清茗
陌清茗 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:17

    To display a TimeSpan formatted with local culture, simply add it to a date like DateTime.Today. Something like this:

    (DateTime.Today + timeSpan).ToString();

    Since your value really doesn't represent a date, you're better off storing it as a TimeSpan until the time comes to display it.

提交回复
热议问题