Roundoff Timespan to 15 min interval

Posted by s-a-n on Stack Overflow See other posts from Stack Overflow or by s-a-n
Published on 2014-06-03T02:33:33Z Indexed on 2014/06/03 3:26 UTC
Read the original article Hit count: 121

Filed under:

I have a property in my code where users can enter a timespan in HH:mm like
10:32
10:44
15:45

I want to round off in my property to the nearest 15mins but i dont have datetime here. I only need to do it with Timespan

10:32 to 10:30
10:44 to 10:45
15:45 to 15:45
01:02 to 01:00
02:11 to 02:15
03:22 to 03:25
23:52 to 00:00

Tried all these solutions but they involve Datetime in them

How can I round up the time to the nearest X minutes?
Is there a simple function for rounding a DateTime down to the nearest 30 minutes, in C#?
DotNet Roundoff datetime to last 15 minutes

© Stack Overflow or respective owner

Related posts about c#