How to convert int 90 minutes to DateTime 1:30


How can I convert an int 90, for example, to DateTime 1:30 in C# 3.0?


Best Answer

You shouldn't use a DateTime to represent a span of time - use TimeSpan for that. And in such a case, you'd use this:

TimeSpan ts = TimeSpan.FromMinutes(90);

If you insist that you need a DateTime, you could do the following:

DateTime dt = DateTime.Now.Date; // To get Midnight Today
dt = dt.AddMinutes(90); // to get 90-minutes past midnight Today.

The reason you probably don't want to use DateTime, though, is that it (aptly named) combines the concept of Date with the concept of Time. Your question suggests that you're planning to ignore the date component, so in the interests of using the right tool for the job, I suggest TimeSpan.