Search code examples
asp.net-coreazure-web-app-service

Datepicker datetime format is not working while running the application in Azure


I am calling the datetime picker to enter the date in dd/mm/yyyy format. I am using the following css and js file in layout file

 <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css" />
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.21/css/jquery.dataTables.min.css" />      
<style rel="stylesheet"
       href="https://cdn.datatables.net/buttons/1.5.2/css/buttons.dataTables.min.css"></style>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/css/toastr.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
@*<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>*@

my view file is given below

<script>
        $("#TaxDate").datepicker({ dateFormat: "dd/MM/yy" });
        $("#MOTDate").datepicker({ dateFormat: "dd/MM/yy" });
        $("#InsuredDate").datepicker({ dateFormat: "dd/MM/yy" });
        $("#RegDate").datepicker({ dateFormat: "dd/MM/yy" });
</script
  <div class="row">
        <div class="col-md-6">
            <div class="form-group  row">
                <label asp-for="Vehicles.MOTDate" class="control-label  col-3 col-form-label">MOT Date</label>
                <div class="col-9">
                    <input class="form-control input-sm" type="text" id="MOTDate"
                           asp-for="Vehicles.MOTDate" />
                    <span asp-validation-for="Vehicles.MOTDate" class="text-danger">@ViewBag.moterror</span>
                </div>
            </div>
        </div>
        <div class="col-md-6">
            <div class="form-group row">
                <label asp-for="Vehicles.TaxDate" class="control-label col-3 col-form-label">Tax Date</label>
                <div class="col-9">
                    <input class="form-control input-sm" type="text" id="TaxDate"
                           asp-for="Vehicles.TaxDate" />
                    <span asp-validation-for="Vehicles.TaxDate" class="text-danger">@ViewBag.taxerror</span>
                </div>
            </div>
        </div>
    </div>

But when I run the published site in azure , the date time 'dd/mm/yyyy' format is not working. it is still working as 'mm/dd/yyyy' . If am going to run in application in localserver it will work . When I run azure it is not working please help to fix


Solution

  • UPDATE

    This problem was finally solved by modifying CultureInfo. The sample code is as follows.

    Setting the following in StartUp.Configure

    var cultureInfo = new CultureInfo("en-US");
    
    CultureInfo.DefaultThreadCurrentCulture = cultureInfo;
    CultureInfo.DefaultThreadCurrentUICulture = cultureInfo;
    

    PRIVIOUS

    Usually we solve this problem, first ensure that there is no problem with the published file, you can use other methods such as FTP to publish, local testing and deployment to Azure testing.