Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7698223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:11:32+00:00 2026-05-31T22:11:32+00:00

Having derived this logic to bind dropdownlist to set of time intervals, I would

  • 0

Having derived this logic to bind dropdownlist to set of time intervals, I would like to get this improved in terms

  • Use native data types designed to date and time

  • Make it configurable

pseudocode

for (var hoursCount = 0; hoursCount <= 12; i++) {
    for (var timeSlots = 0; timeSlots < 2; j++) {
        string hourAndMinute = hoursCount;
        if (timeSlots == 0) {
            hourAndMinute += ":00 AM";
        } else {
            hourAndMinute += ":30 AM";
        }
        if (hourAndMinute != "12:00 AM" || hourAndMinute != "12:30 AM") {
            alert(hourAndMinute);
        }
    }
}

Output

0:00 AM

0:30 AM

.
.
.

12:30 AM
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T22:11:33+00:00Added an answer on May 31, 2026 at 10:11 pm

    It’s unclear what sort of “configuration” you want here, but as you’re only dealing with a time, I would personally use Noda Time which has the LocalTime struct for handling this sort of thing. (Disclaimer: I’m the main developer on Noda Time, so I’m somewhat biased.) You could just use DateTime, but as you don’t want a date…

    It’s not really clear what kind of “configuration” you want, but in Noda Time you could write:

    LocalTimePattern pattern = LocalTimePattern.CreateWithInvariantInfo("hh:mm tt");
    for (var hour = 0; hour <= 12; hour++) {
        for (var slot = 0; slot < 2; slot++) {
            LocalTime time = new LocalTime(hour, slot * 30, 0);
            Console.WriteLine(pattern.Format(time));            
        }
    }
    

    With more details of what you want to do, we can no doubt help more.

    EDIT: Okay, it sounds like maybe you want something like:

    static void DisplaySlots(string format, Period slotLength, int slots)
    {
        // Or change the parameter to be a LocalTimePattern
        LocalTimePattern pattern = LocalTimePattern.CreateWithInvariantInfo(format);
        LocalTime time = LocalTime.Midnight;
        for (int i = 0; i < slots; i++)
        {
            Console.WriteLine(pattern.Format(time));
            time = time + slotLength;
        }
    }
    

    Then call it with:

    DisplaySlots("HH:mm", Period.FromMinutes(20), 100);
    

    (Or whatever…)

    Alternative using DateTime:

    static void DisplaySlots(string format, TimeSpan slotLength, int slots)
    {
        DateTime time = DateTime.Today;
        for (int i = 0; i < slots; i++)
        {
            Console.WriteLine(time.ToString(format));
            time = time + slotLength;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having a heckuva time with this one, though I feel I'm missing something obvious.
Having something like this this : public abstract class AAA { protected abstract virtual
Is there anyway of having a base class use a derived class's static variable
Having trouble inheriting from a template class. Looks something like this: template<typename type> class
Like many before me, I'm trying so get my derived types to automatically register
I'm having a problem sorting my derived classes with the STL sort function. Example
I am having a bit of a struggle with Expressions inside SSIS Derived Columns.
I'm having a bit of trouble figuring out how to make this repository pattern
Taking Sql this quarter and not having any luck with the following question: The
I had this idea and my first reaction after having it was That's a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.