I want to convert the int value 600
to 06:00
and 1700
to 17:00
in C#.
This is what I have tried so far:
int val = 600;
TimeSpan result = TimeSpan.FromHours(val);
string fromTimeString = result.ToString("hh':'mm");
How can this be achieved?
If you have only hours and minutes you can create the TimeSpan
like this:
// Assuming val is always valid:
TimeSpan result = new TimeSpan(val / 100, val % 100, 0);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.