Allan Snicker
Allan Snicker

Reputation: 9

Output value with TimeSpan without seconds

I ran into a problem. I have property

TimeSpan StartedStudy {get; set;} 

I need just initialize this property using TimeSpan

How I make it.

StartedStudy = TimeSpan.FromHours(10);

Output: 10:00:00

What I have ? I have 10(hours), 00(minutes) and 00(seconds), but I don't need output seconds, I need

Output: 10:00 without seconds.

Warning: How to cut seconds without converting to string ?

Upvotes: 0

Views: 153

Answers (1)

Racil Hilan
Racil Hilan

Reputation: 25351

The TimeSpan and DateTime types are not stored internally as you see them. Internally, they are just numbers like Integer and Long. Wherever you see the TimeSpan as 10:00:00, you are actually looking at its string representation. There is no concept of hours, minutes, and seconds separately in the TimeSpan, so you cannot remove one of them. They're all one single number. You'll have to convert them to string before you can display them in any human readable way.

Upvotes: 1

Related Questions