在将时间格式从完整日历开始时间转换为c#时间范围时出错
Error in conversion of time format from full calendar start time to C# timespan
我试图将fullcalendar返回的事件开始时间转换为在动作方法中使用c# timespan对象的模型绑定。fullcalendar为开始时间赋值的格式是"May 24, 2015 6:30 AM"。但是在ModelState中,我得到以下错误"值'May 24,2015 6:30 AM'对StartTime无效。"。在事件模式中,我必须以上述格式显示开始时间(2015年5月24日上午6:30)。但希望它模型绑定正确的时间跨度对象。有什么帮助吗?
关于场景的更多信息:
这是我在日历javascript中显示自定义日期时间格式的代码$ (" # StartTimeTxtBox").val(时刻(start) .format("微光"));显示时间为"May 24, 2015 6:30 AM"。我试图将此绑定到"公共TimeSpan StartTime {get;设置;}"在我的动作方法,它导致错误"值'May 24, 2015 6:30 AM'是无效的开始时间"。在绑定到服务器变量之前是否有任何方法进行转换?enter code here
更新#1:为了更清晰,我发布了这部分代码。
完整日历javascript:
<>之前select: function (start, end, allDay) {$('#modalTitle').html("添加一个新事件");//$ (' # modalBody ') . html("Hello world");$ (" # StartTimeTxtBox").val(时刻(start) .format("微光"));$ (" # EndTimeTxtBox").val(时刻(结束).format("微光"));$ (' # AppointmentDate ') .val(时刻(开始)。格式(YYYY-MM-DD hh: mm: ss));$ (" # PatientStatement")。val('请添加一些关于疾病的描述');$ (" # DoctorClinicID ") .val (@ViewBag.DoctorClinicID);$ (' # calendarModal ') .modal ();calendar.fullCalendar("取消选择");refreshCalendar ();}之前 StartTime文本框的标记:<input type='text' id="StartTimeTxtBox" class="form-control sharp-edge" placeholder="Start Time" name="StartTime" />
c#视图模型:
<>之前公共类任命模型{public int appointment{获取;设置;}public int DoctorClinicID {get;设置;}公共字符串医生名称{获取;设置;}公共日期时间任命日期{获取;设置;}公共时间跨度开始时间{获取;设置;}公共时间跨度结束时间{获取;设置;}public DateTime开始{得到{var ret =约会日期;ret = ret. add (StartTime);返回受潮湿腐烂;}}public DateTime结束{得到{var ret =约会日期;ret = ret. add (EndTime);返回受潮湿腐烂;}}public int PatientID {get;设置;}公共字符串PatientName{获取;设置;}公共任命状态{get;设置;}public int TokenNumber {get;设置;}公共字符串PatientStatement {get;设置;}公共字符串ClinicComments {get;设置;}}之前操作方法:<>之前public JsonResult SaveAppointment(AppointmentModel){int任命= 0;如果(ModelState.IsValid){Appointment = new Appointment{约会日期=约会模型。AppointmentDate,StartTime = appointmentModel。开始时间,EndTime = appointmentModel。EndTime,任命状态id = 1,ClinicComments = appointmentModel。ClinicComments,DoctorClinicID = appointmentModel。DoctorClinicID,PatientID = appointmentModel。PatientID,PatientStatement = appointmentModel。PatientStatement,};appointment = repository.SaveAppointment(appointment);}返回Json(任命,JsonRequestBehavior.AllowGet);}
您需要使用LT
或hh:mm
momentjs格式而不是LLL
。ll格式包括日期组件,您只需要时间组件。
。把
$("#StartTimeTxtBox").val(moment(start).format('LLL'));
$("#EndTimeTxtBox").val(moment(end).format('LLL'));
$('#AppointmentDate').val(moment(start).format('YYYY-MM-DD hh:mm:ss'));
$("#StartTimeTxtBox").val(moment(start).format('LT'));
$("#EndTimeTxtBox").val(moment(end).format('LT'));
$('#AppointmentDate').val(moment(start).format('YYYY-MM-DD'));
或
$("#StartTimeTxtBox").val(moment(start).format('hh:mm'));
$("#EndTimeTxtBox").val(moment(end).format('hh:mm'));
$('#AppointmentDate').val(moment(start).format('YYYY-MM-DD'));
- 将日期和时间转换为UTC格式的日期-Javascript
- 用JavaScript将ISO时间转换为H:MM am|pm
- 用javascript将epoch时间转换为可读格式
- 将时间转换为UTC时出现故障
- 将日期和时间转换为UTC
- 将JSON中的时间转换为实际播放PHP的时间
- JavaScript日期&时间转换tz到正常
- 在 javascript 中将 24 小时时间转换为 12 小时,运行秒数
- Javascript将时间转换为CET
- 在mirth connect中,将本地时间的hl7日期时间转换为UTC的iso日期
- 反转历元时间转换
- 如何使用MongoDB和Mongoose/Express将UTC时间转换为本地时间,反之亦然
- 使用mommtjs将某个时区的时间转换为UTC
- 将 MYSQL 时间转换为 EST
- JavaScript:如何使用纯Javascript将UTC日期时间转换为EST Hours
- 使用 JavaScript 从日期时间转换为短日期格式
- 使用 JavaScript 或 jQuery 将 UTC 日期时间转换为本地日期时间
- 在 JavaScript 中将 Unix 时间转换为“几分钟前”
- 将 JSON 日期时间转换为 JavaScript 日期时,它显示为比本地时区早 1 天
- 显示错误值的高图表日期时间转换