$("#datetim...">

JQuery datetimepicker for python datetime

I have below jQuery Datetimepicker

<input type="text" name="datetime" id="datetime">
$("#datetime").datetimepicker({
    controlType: 'select',
    oneLine: true,
    timeFormat: 'hh:mm tt'
});

I am posting the date as an AJAX POST request in Django:

const starts = $('#datetime').val();
$.ajax({
    type: 'POST',
    url: '/booking/new/',
    data: {
        starts: starts,
    },
};

In Django, I get the value:

if request.method == 'POST':
    starts = request.POST.get('starts')
    object.starts = datetime.strptime(starts, '%x %I:%M %p')

I get the following error:

ValueError: time data '11 / 12/2016 12:00 am 'does not match the format'% x% I:% M% p '

I tried different formats, but I can not find the correct one. Can I create a format from a string value in some way?

+4
source share
1 answer

You can define a default datetime format, for example this, follow the following rule

+1
source

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


All Articles