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 8414721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:14:16+00:00 2026-06-10T01:14:16+00:00

Since jQuery datepicker has no time to select, I used the following TimeSpan code

  • 0

Since jQuery datepicker has no time to select, I used the following TimeSpan code which returned two dropdownlists for hours (0-23) and minutes (0-59). This is working fine. However, I need 12-hour format with AM/PM dropdownlist.

 @model TimeSpan


@Html.DropDownList("hours", Enumerable.Range(0, 24)
                       .Select(i => new SelectListItem
                           {
                             Value = i.ToString(),
                             Text = i.ToString(), 
               //Selected = (Model.Hours > 12 ? Model.Hours - 12 : Model.Hours) == i
                             Selected = Model.Hours == i
                           }
                  )) 

@Html.DropDownList("minutes", Enumerable.Range(0, 60)
                       .Select(j => new SelectListItem
                           {
                             Value = j.ToString(),
                             Text = j.ToString(), 
                             Selected=Model.Minutes == j
                           }
                  ))

I added the following code to display AM/PM dropdownlist. However, I need to modify the code to display 12-hour format with AM/PM dropdownlist:

@Html.DropDownList("ampm",  Enumerable.Range(0,2)
   .Select(t =>  new SelectListItem
            {
              Value = t.ToString(),
              Text = (t == 0 ? "AM" : "PM"),                       
              Selected = (Model.Hours > 11 ? 1 : 0) == t
            }  
          ))   

I need help modifying the below TimeBinder class for 12 hour format with AM/PM dropdownlist.

public class TimeBinder : IModelBinder
    {         
        object IModelBinder.BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {            
            //Ensure there's incoming data
            //*************************
            //*** Validate "HOURS"  ***
            //*************************
            var hoursKey = bindingContext.ModelName; //key = EODTime
            var hoursValueProviderResult = bindingContext.ValueProvider.GetValue(hoursKey + ".hours"); //valueProviderResult = {15} (for selection of 15:10); RawValue has array of 15           

                if ((hoursValueProviderResult == null) ||
                   string.IsNullOrEmpty(hoursValueProviderResult.AttemptedValue))
                {
                    return null;
                }

                //Preserve it in case we need to redisplay the form
                bindingContext.ModelState.SetModelValue(hoursKey, hoursValueProviderResult);

                //Parse
                var hours = ((string[])hoursValueProviderResult.RawValue)[0];

                //**************************
                //*** Validate "MINUTES" *** 
                //**************************          
                var minuteKey = bindingContext.ModelName; //key = EODTime
                var minutesValueProviderResult = bindingContext.ValueProvider.GetValue(minuteKey + ".minutes"); 

                //valueProviderResult = {10} (for selection of 15:10); RawValue has array of 10           

                if ((minutesValueProviderResult == null) ||
                   string.IsNullOrEmpty(minutesValueProviderResult.AttemptedValue))
                {
                    return null;
                }

                //Preserve it in case we need to redisplay the form
                bindingContext.ModelState.SetModelValue(minuteKey, minutesValueProviderResult);

                //Parse           
                var minutes = ((string[])minutesValueProviderResult.RawValue)[0];


                //A TimeSpan represents the time elapsed sice midnight
                var time = new TimeSpan(Convert.ToInt32(hours), Convert.ToInt32(minutes), 0);

                return time;

            }  
       } 
  • 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-06-10T01:14:18+00:00Added an answer on June 10, 2026 at 1:14 am

    Please look at the following: http://trentrichardson.com/examples/timepicker/

    I use it all the time. It’s simple, yet powerful as it extends jQueryUI so the theme roller, localization etc. works like a charm.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form which includes a JQUERY datepicker attatched to an <input> on
jQuery has an attr() method which retrieves the value of a given HTML attribute.
I thus far used YUI Datatable to render all my records... Since Jquery is
since jQuery 1.4 removeClass(); now takes a function as argument. My <body> tag has
Hi i am using jquery-ui datepicker to select date and date.js to find difference
As we all know, since jQuery 1.7: $('someSelector').live('click', fn()); has become, essentially: $(document).on('click', 'someSelector',
I have a malfunctioning set of jquery datepickers that are only not working since
Since regular jQuery animations are not fluent on iOS ( .hide() , slideDown() ),
Edit (2012-04-12): Since this question was asked it is now possible (as of jQuery
I am newbie to jQuery , just trying to learn it since last couple

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.