locked
Datetime formatting differences on productionserver VS development pc RRS feed

  • Question

  • User-959394753 posted

    Hi,

    I am developing a app that is making intensive use of Datetime calculations. On my development machine I have my Regional setting on Dutch.

    I am hosting my app on a server in the UK. Now when I set in razor a HTML data field with a Datetime value like this: 

    data-datum=@Model.LinesList[i].DayList[ii].Datum.ToString("yyyy-MM-dd")

    On my development machine it renders with "-" between the year, Month and Day component. but on the UK server a "/" is appearing.

    Since I am using this Date in Jquery selections, things go very wrong.

    Is there a way to force the production server to use the Dutch formatting? Or is there an other trick to make this working?

    Monday, August 26, 2019 10:15 AM

Answers

  • User1289604957 posted

    Hello Rob,

    You can use the following middleware in the Startup.cs file for your production:

    var supportedCultures = new[]
    {
        new CultureInfo("nl-NL"),
        new CultureInfo("en-GB"),
    };
    
    app.UseRequestLocalization(new RequestLocalizationOptions
    {
        DefaultRequestCulture = new RequestCulture("nl-NL"),
        // Formatting numbers, dates, etc.
        SupportedCultures = supportedCultures,
        // UI strings that we have localized.
        SupportedUICultures = supportedCultures
    });
    
    app.UseStaticFiles();
    // To configure external authentication, 
    // see: http://go.microsoft.com/fwlink/?LinkID=532715
    app.UseAuthentication();
    app.UseMvcWithDefaultRoute();

    Best regards,

    Maher

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 26, 2019 10:32 AM

All replies

  • User1289604957 posted

    Hello Rob,

    You can use the following middleware in the Startup.cs file for your production:

    var supportedCultures = new[]
    {
        new CultureInfo("nl-NL"),
        new CultureInfo("en-GB"),
    };
    
    app.UseRequestLocalization(new RequestLocalizationOptions
    {
        DefaultRequestCulture = new RequestCulture("nl-NL"),
        // Formatting numbers, dates, etc.
        SupportedCultures = supportedCultures,
        // UI strings that we have localized.
        SupportedUICultures = supportedCultures
    });
    
    app.UseStaticFiles();
    // To configure external authentication, 
    // see: http://go.microsoft.com/fwlink/?LinkID=532715
    app.UseAuthentication();
    app.UseMvcWithDefaultRoute();

    Best regards,

    Maher

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 26, 2019 10:32 AM
  • User-959394753 posted

    Jou are my hero!

    works excellent.

    Monday, August 26, 2019 11:12 AM