bootstrap-datetimepicker error date format, Asp Mvc

0

I have in one view an inputbox on which I am using bootstrap-datetimepicker to capture the date, this DTP has the format 'YYYY / MM / DD':

<script type="text/javascript"> $(function () { $('#datetimepicker1').datetimepicker({format:'YYYY/MM/DD', locale:'es-MX'}); }); </script>

When the view starts the controller sends a date value as '10 / 06/2016 'but the problem is that the view shows me' 0010/06/20 '.

If I change the format in the script, the date that the view is received through the controller is displayed correctly, but a problem arises when selecting a DateTimePicker value since any date higher than day 12 takes it as invalid. ..

'<script type="text/javascript">
    $(function () {
        $('#datetimepicker1').datetimepicker({format:'DD/MM/YYYY', locale:'es-MX'});
    });
</script>'

How to solve this format problem?

    
asked by jose luis garcia 10.06.2016 в 23:53
source

1 answer

4

In the controller you must change the date format, in such a way you save the problem in the client, here is a list of examples:

// números de mes/día sin o con ceros:
String.Format("{0:M/d/yyyy}", dt);            // "3/9/2008"
String.Format("{0:MM/dd/yyyy}", dt);          // "03/09/2008"

// nombres día/mes
String.Format("{0:ddd, MMM d, yyyy}", dt);    // "Do, Mar 9, 2008"
String.Format("{0:dddd, MMMM d, yyyy}", dt);  // "Domingo, Marzo 9, 2008"

// dos/cuatro dígitos para el año
String.Format("{0:MM/dd/yy}", dt);            // "03/09/08"
String.Format("{0:MM/dd/yyyy}", dt);          // "03/09/2008"

Extracted from: link

Update

Considering the comment of @jose luis garcia, in the Model can also be defined as follows:

 [DisplayFormat(DataFormatString = "{0:dd.MM.yyyy}")]
 public DateTime CampoDeFecha{ get; set; }
    
answered by 11.06.2016 / 00:00
source