How to create a list with hours and minutes based on interval

In the days of VB.NET I used to use two drop-downs to determine the hour and the minute of an import via the following manner:

For i As Integer = 0 To 23
ddlHour.Items.Add(New ListItem(String.Format("{0:0#}", i), i.ToString()))
For i As Integer = 0 To 45 Step 15
ddlMinute.Items.Add(New ListItem(String.Format("{0:0#}", i), i.ToString()))

I’ve had a play with the TimeSpan object and found an easy way to print the hours and mins using c#

private List LoadHours(int NumberOfMinutes)
            var ts = TimeSpan.Zero;
            var ts_end =TimeSpan.FromDays(1);

            var lstReturn = new List();

            while (ts<ts_end)

                ts = ts.Add(TimeSpan.FromMinutes(NumberOfMinutes));
            return lstReturn;

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.