Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I am trying to create a parking app in MVC 4.

To register a car parking on a parking lot I need to have a field where I can set time and date marking the start of parking.

Right now I have a model with data annotations:
C#
[Display(Name = "Parking Start Time")]
[DataType(DataType.Date), DisplayFormat(DataFormatString = "{0:HH:mm dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime ParkingStartTime { get; set; }


And in View:
HTML
<div class="editor-label">
            @Html.LabelFor(vm => vm.newCarOnParkingSpot.ParkingStartTime)
        </div>
        <div class="editor-field">
            @Html.EditorFor(vm => vm.newCarOnParkingSpot.ParkingStartTime)
            @Html.ValidationMessageFor(vm => vm.newCarOnParkingSpot.ParkingStartTime)
        </div>


This gives me neat resault for date picking, but no time entering option:
Image

The reason I use formating is because the original DateTime format(US) does not suit my application. I would like to have it as close to - HH:mm dd/MM/yyyy - as I can.

What options do I have for getting date and also time from the user?

I have searched for solutions but somehow missed similar problems. Maybe I'm approching this problem from a wrong angle. Please be gentle, it's my first question.

Thank you in advance!
Posted
Updated 21-Jul-15 3:14am
v2

1 solution

USE
public TimeSpan ParkingStartTime { get; set; }
in the model in case only time needed.
ELSE
public DateTime ParkingStartTime { get; set; }
USE datetime picker in JS.
$('#datepicker').datetimepicker({
dateFormat: "dd/MM/yyyy",
timeFormat: "HH:mm"
});
 
Share this answer
 
v2
Comments
Slevender 22-Jul-15 2:33am    
Yes. Thank you. For the end of the day I managed to find jQuery dateTimePicker on my own too. But thanks for replying!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900