Daterangepicker字段显示无效日期 [英] Daterangepicker field shows invalid date

查看:612
本文介绍了Daterangepicker字段显示无效日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在开发一个在.NET MVC中开发的项目,我面临着一个关于daterangepicker功能的问题。相同的功能适用于localhost,但不适用于托管我的应用程序的服务器。我正在使用bootstrap daterangepicker类。控制器和JavaScript中的日期格式相同。我将附上控制器和JavaScript的代码。



实际工作:

从daterangepicker中选择日期范围,并填写其余字段。完成此步骤后,单击保存按钮,将保存详细信息。一旦保存,我可以提交它并成功提交。



问题:

第一次保存后,当我导航到在同一页面进行修改时,daterangepicker显示无效日期。这适用于localhost,但不适用于生产服务器。



我已就此问题与托管支持团队进行了沟通,但他们的结果并没有错。如果有人以前遇到过这个问题,请告诉我。





控制器代码:

I am working on a project developed in .NET MVC where I am facing an issue regarding a daterangepicker functionality. The same functionality works on localhost but not on server where my application is hosted. I am using bootstrap daterangepicker class. The date format is same in the controller and the JavaScript. I’ll attach the code of the controller and the JavaScript.

Actual working :
A daterange is selected from the daterangepicker and the remaining fields are filled. After this step, I click on Save button and the details are saved. Once it is saved I can submit it and it gets submitted successfully.

Problem:
After saving the first time, when I navigate to the same page for modification, the daterangepicker shows invalid date. This works on localhost but not on the production server.

I have communicated with the hosting support team regarding this issue but there is nothing wrong from their end. Please let me know if anyone has faced this issue before.


Controller Code:

if (count == 1)
                    {
                        daterange = r.DateRange.Split('/');
                        fmdate = daterange[0].Trim();
                        todate = daterange[1].Trim();
                        tm.UserId = obj.UserId;
                        //DateTime fordate = DateTime.ParseExact("05/03/2018", "dd/MM/yyyy", CultureInfo.InvariantCulture);
                        tm.FromDate = DateTime.ParseExact(fmdate, "dd-MM-yyyy", CultureInfo.InvariantCulture);
                        tm.EndDate = DateTime.ParseExact(todate, "dd-MM-yyyy", CultureInfo.InvariantCulture);
                        tm.IsSubmited = false;
                        tm.IsApproved = false;
                        entity.TimesheetMasters.Add(tm);
                        entity.SaveChanges();



JavaScript代码:


JavaScript Code:

<script>
        $('#daterange').daterangepicker({

            "dateLimit": {
                "days": 5
            },
            "locale": {

                "format": "DD-MM-YYYY",
                "separator": " / ",
                "applyLabel": "Apply",
                "cancelLabel": "Cancel",
                "fromLabel": "From",
                "toLabel": "To",
                "customRangeLabel": "Custom",
                "weekLabel": "W",
             
                "firstDay": 1
            },
            "weekStart": 5,
            "showWeekNumbers": true,


        });
    </script>





我尝试过:



我尝试使用不同的日期格式,但它不起作用。



What I have tried:

I have tried using different date formats but it didn't work.

推荐答案

('#daterange')。daterangepicker( {

dateLimit:{
days:5
},
locale:{

format: DD-MM-YYYY,
分隔符:/,
applyLabel:申请,
cancelLabel:取消,
fromLabel :From,
toLabel:To,
customRangeLabel:Custom,
weekLabel:W,

firstDay:1
},
weekStart:5,
showWeekNumbers:true,


});
< / script>
('#daterange').daterangepicker({ "dateLimit": { "days": 5 }, "locale": { "format": "DD-MM-YYYY", "separator": " / ", "applyLabel": "Apply", "cancelLabel": "Cancel", "fromLabel": "From", "toLabel": "To", "customRangeLabel": "Custom", "weekLabel": "W", "firstDay": 1 }, "weekStart": 5, "showWeekNumbers": true, }); </script>





我尝试过:



我尝试过使用不同的日期格式但是没有用。



What I have tried:

I have tried using different date formats but it didn't work.


你检查了日期格式吗?



它应该和本地一样。



您可以将服务器日期格式设置为本地格式,也可以根据服务器转换日期格式部署前的日期格式。
Have you checked the date format ?

It should be same as local.

Either you can set your server date format as your local or you may convert date format according server date format before deployment.


这篇关于Daterangepicker字段显示无效日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆