Retrieving DateTime Data Using MVC

Problem to be resolved:

  • Getting time and date from MVC application

My specific problem: I have a parking management application. Since you can reserve a parking space in front, I need to know the time and date of the parking start. For my model, I used DateTime because MSDN declares it as a full-featured time and date data type:

The .NET Framework DateTime class provides a full-featured interface for writing time-related programs.

My research. I was looking for answers or typical solutions (best practices) for this problem, and almost everything I had was:

  • problems with globalization
  • problems with time zones
  • various date formats

But nothing takes into account how convenient and convenient it is to use the date and time using the MVC application.

The closest answer I found is Scott Hanselman's 2009 solution - http://www.hanselman.com/blog/SplittingDateTimeUnitTestingASPNETMVCCustomModelBinders.aspx

Other solutions that people tend to use are different jQuery plugins.

For me, these decisions seem overly complicated. Since I do not know where else to ask, and if these are the only solutions or not, my question is:

  • What are my options for getting time and date using MVC - best practice?

In my model, I use:

[DataType(DataType.DateTime), DisplayFormat(DataFormatString = "{0:HH:mm dd/MM/yyyy}", ApplyFormatInEditMode = true)]
    public DateTime? ParkingStartTime { get; set; }

In my opinion, I use:

 <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 solution gives me a datepicker HTML5 date, but there is no time insertion option: http://i.stack.imgur.com/fGPTV.png


, , , , .

+4
1

@SLC , jQuery. jQuery DateTimePicker http://xdsoft.net/jqplugins/datetimepicker/

SLC:

, jquery date picker

. 7 .

, , :

  • jQuery DateTimePicker ( )
  • , ( 2 script 1 css cshtml, jQuery id - Voila!)
  • 0 , , db DateTime

, - jQuery. , ?:

<script type="text/javascript">
$(document).ready(function () {
    jQuery('#datetimepicker').datetimepicker();
});

0

Source: https://habr.com/ru/post/1598907/


All Articles