0
votes

I've been searching for like an hour now but I can't seem to find a good DateTimePicker for ASP.NET MVC, and let me emphasize, I need a DateTimePicker not a DatePicker. In other words it should also have a time (hour, minutes, seconds) to choose while choosing the date. I would prefer if it is a nugget. I am using the latest version of .NET, but I don't know if there is a default DateTimePicker.

2
you might want to have a bit of a read of the question guidelines John. It's a fair question in general terms, but here on SO these tend to get closed because they end up being a debate between different gizmos and get opinionated. You might be able to recover by describing some things you've tried, and how they have worked for you... or what you specifically hate about them - Tim Ogilvy

2 Answers

2
votes

I recommend:

https://flatpickr.js.org/
https://github.com/flatpickr/flatpickr

IE9+, Edge, FF, and Chrome work fine with this Datetimepicker. Mobile is supported. It doesn't depend on any libraries.

    <!-- include css and js --> 
    <link rel="stylesheet"href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css">
    <script src="https://cdn.jsdelivr.net/npm/flatpickr"></script>

    <!-- html --> 
    <div id="flatpickrcontainer">
    <input type="text" id="time" placeholder="Select Date.." data-input>    
    </div>

    <script>   

    // js initialization

    flatpickr.l10ns.default.firstDayOfWeek = 1; // Monday default is sunday

    document.getElementById("flatpickrcontainer").flatpickr({
        wrap: true,           
        weekNumbers: true, 
        enableTime: true, // enables timepicker default is false    
        time_24hr: true, // set to false for AM PM default is false
        onChange: function (selectedDates, dateStr, instance) {
            console.log("changed");          
        }
    });
    </script>

More examples: https://flatpickr.js.org/examples/

0
votes

You can use the datetime-local input type. It works in Chrome and Edge, however it does not work in Firefox.

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/datetime-local

https://caniuse.com/#feat=input-datetime

<input id="datetime" type="datetime-local" />