[英]How to correct the time on Fullcalendar using Ajax And Flask?
当我在日历上进行约会时,开始时间和结束时间正确显示,但是重新加载页面后,我在日历上和数据库内部获得了不同的日期时间。
因此,例如,如果我从09:00 AM到10:30 AM进行了约会,在数据库中我得到了:
开始时间 :2017-04-30 15:00:00
结束时间 :2017-04-30 16:30:00
我的view.py :
appointment = Appointment()
appointment.start_time = parse_appoitment(start)
appointment.end_time = parse_appoitment(end)
appointment.note = data
appointment.user_id = abonent.id
appointment.client_id = client.id
db.session.add(appointment)
db.session.commit()
还有日期解析器 :
def parse_appoitment(time):
start_datime = str(time)[0:25]
date = parse(start_datime)
return date.strftime('%Y-%m-%d %H:%M:%S')
这是javascript
代码:
{% if client.is_subscriber(master.id) %}
$(document).ready(function() {
var initialLocaleCode = 'ru';
var d = new Date();
var strDate = d.getFullYear() + "/" + (d.getMonth()+1) + "/" + d.getDate();
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay,listMonth'
},
defaultDate: moment(),
// month basicWeek basicDay agendaWeek agendaDay listYear listMonth listWeek listDay
defaultView: 'agendaWeek',
height: 650,
locale: initialLocaleCode,
local: 'GMT+06:00',
navLinks: true, // can click day/week names to navigate views
selectable: true,
selectHelper: true,
select: function(start, end) {
if(start.isBefore(moment())) {
$('#calendar').fullCalendar('unselect');
return false;
} else {
$(this).css({"cursor":"pointer"});
}
var title = prompt('Event Title:');
var eventData;
if (title) {
eventData = {
title: title,
start: start,
end: end
};
$('#calendar').fullCalendar('renderEvent', eventData, true); // stick? = true
// console.log(eventData);
$.ajax({
type: 'POST',
url: '{{url_for("client.get_appo", abonent=master.slug)}}',
// contentType: 'application/json;charset=UTF-8',
data: {
'title': title,
'start': eventData['start']['_d'],
'end': eventData['end']['_d']
}
})
.done(function(data){
if(data.error){
// console.log(data.data);
console.log(eventData['start']['_d']);
}
else {
// console.log(data.data);
console.log(eventData['start']['_d']);
}
});
}
},
editable: true,
eventLimit: true, // allow "more" link when too many events
events: [
{% for appo in master.appointments %}
{% if appo.is_not_accepted %}
{% endif %}
{
"title": "{{appo.note}}",
"start": "{{appo.start_time}}",
"end": "{{appo.end_time}}"
},
{% endfor %}
]
});
// build the locale selector's options
$.each($.fullCalendar.locales, function(localeCode) {
$('#locale-selector').append(
$('<option/>')
.attr('value', localeCode)
.prop('selected', localeCode == initialLocaleCode)
.text(localeCode)
);
});
// when the selected option changes, dynamically change the calendar option
$('#locale-selector').on('change', function() {
if (this.value) {
$('#calendar').fullCalendar('option', 'locale', this.value);
$(this).css({'background-color':'red'});
}
});
});
{% endif %}
我不确定此local: 'GMT+06:00',
添加了它,或者我每次都得到的不是一样的东西。
编辑:
我忘记输入提交约会后和解析之前的格式:
Sun Apr 23 2017 15:30:00 GMT+0600 (+06)
Sun Apr 23 2017 17:00:00 GMT+0600 (+06)
Sun Apr 23 2017 15:30:00 GMT+0600 (+06)
至Sun Apr 23 2017 17:00:00 GMT+0600 (+06)
在这里,我从09:30到11:00做了一个,但是我得到了上述结果。
您必须在设置中将时区设置为本地,如下所示:
timezone: 'local'
现在它可以工作了:)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.