Javascript 如何使用Ajax和Flask更正Fullcalendar上的时间?
当我在日历上预约时,开始时间和结束时间显示正确,但在重新加载页面后,我在日历上和数据库中得到了不同的日期时间 例如,如果我预约了从上午9:00到上午10:30的时间,在数据库中我得到以下信息: 开始:2017-04-30 15:00:00 结束:2017-04-30 16:30:00 我的视图.py:Javascript 如何使用Ajax和Flask更正Fullcalendar上的时间?,javascript,ajax,fullcalendar,Javascript,Ajax,Fullcalendar,当我在日历上预约时,开始时间和结束时间显示正确,但在重新加载页面后,我在日历上和数据库中得到了不同的日期时间 例如,如果我预约了从上午9:00到上午10:30的时间,在数据库中我得到以下信息: 开始:2017-04-30 15:00:00 结束:2017-04-30 16:30:00 我的视图.py: appointment = Appointment() appointment.start_time = parse_appoitment(start) appointment.end_time
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')
以及日期解析器:
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 %}
{%if client.is_subscriber(master.id)%}
$(文档).ready(函数(){
var initialLocaleCode='ru';
var d=新日期();
var strDate=d.getFullYear()+“/”+(d.getMonth()+1)+“/”+d.getDate();
$(“#日历”).fullCalendar({
标题:{
左:“上一个,下一个今天”,
中心:'标题',
右图:“月、agendaWeek、agendaDay、listMonth”
},
defaultDate:moment(),
//月基本周基本日代理周代理日期列表年列表月列表周列表日
defaultView:'agendaWeek',
身高:650,
区域设置:initialLocaleCode,
当地时间:“格林尼治时间+06:00”,
navLinks:true,//可以单击日/周名称来导航视图
是的,
selectHelper:对,
选择:功能(开始、结束){
if(start.isBefore(矩())){
$(“#日历”).fullCalendar('unselect');
返回false;
}否则{
$(this.css({“游标”:“指针”});
}
var title=prompt('事件标题:');
var事件数据;
如果(标题){
事件数据={
标题:标题,,
开始:开始,
完:完
};
$(“#calendar”).fullCalendar('renderEvent',eventData,true);//stick?=true
//console.log(eventData);
$.ajax({
键入:“POST”,
url:“{url\u for(“client.get\u appo”,abont=master.slug)}”,
//contentType:'application/json;charset=UTF-8',
数据:{
“标题”:标题,
“开始”:事件数据[“开始”][“开始”],
“结束”:事件数据['end'][''u d']
}
})
.完成(功能(数据){
if(data.error){
//console.log(data.data);
日志(eventData['start']['u d']);
}
否则{
//console.log(data.data);
日志(eventData['start']['u d']);
}
});
}
},
是的,
eventLimit:true,//当事件太多时允许“更多”链接
活动:[
{master.appoints%中appo的%
{如果appo.is_not_accepted%}
{%endif%}
{
“标题”:“{appo.note}”,
“开始”:“{appo.start_time}”,
“结束”:“{appo.end_time}”
},
{%endfor%}
]
});
//生成区域设置选择器的选项
$.each($.fullCalendar.locales,函数(localeCode){
$('#区域设置选择器')。追加(
$('')
.attr('value',localeCode)
.prop('selected',localeCode==initialLocaleCode)
.text(localeCode)
);
});
//当所选选项更改时,动态更改日历选项
$(“#区域设置选择器”)。在('change',function()上{
if(该值){
$('#calendar').fullCalendar('option','locale',this.value);
$(this.css({'background-color':'red'});
}
});
});
{%endif%}
我不确定通过这个本地:'GMT+06:00',
,weither添加了它,或者不是我每次都得到的东西
编辑:
我忘记了在提交约会后和解析约会前键入的格式:
2017年4月23日星期日15:30:00 GMT+0600(+06)
至2017年4月23日星期日17:00:00 GMT+0600(+06)
在这里,我从09:30到11:00制作了一个,但是我得到了上面的结果。您必须在您的设置中将时区设置为本地,如下所示:
时区:“本地”
现在它工作了:)