Sunday, June 16, 2024
HomeiOS Developmentc# - DateTime format not displaying accurately on iPhone in ASP.NET internet...

c# – DateTime format not displaying accurately on iPhone in ASP.NET internet utility


I’ve a razor pages internet utility that exhibits DateTimes all through the applying. Every little thing works nice on a desktop browser in any respect media sizes (together with cell). However once I view the applying on my iPhone (utilizing Safari or Google Chrome) the DateTime codecs don’t present the identical as they might on desktop.

For instance, a DateTime worth of 2024-06-15 11:25:54 PM on Desktop, will present as 2024-06-15 11:25:54 p.m on cell.

That is my program.cs file:

// Early init of NLog to permit startup and exception logging, earlier than host is constructed
var logger = NLog.LogManager.Setup().LoadConfigurationFromAppSettings().GetCurrentClassLogger();

strive
{
    var builder = WebApplication.CreateBuilder(args);

    builder.Configuration.AddEnvironmentVariables();

    CultureInfo tradition = new CultureInfo("en-CA");
    tradition.DateTimeFormat = new DateTimeFormatInfo
    {
        ShortDatePattern = "yyyy-MM-dd",
        LongDatePattern = "yyyy-MM-dd hh:mm:ss tt",
        ShortTimePattern = "hh:mm:ss tt",
        LongTimePattern = "hh:mm:ss tt",
        FullDateTimePattern = "yyyy-MM-dd hh:mm:ss tt",
        DateSeparator = "-",
        TimeSeparator = ":"
    };

    builder.Providers.Configure<RequestLocalizationOptions>(choices =>
    {
        var supportedCultures = new[]
         {
        new CultureInfo("en-CA"),
    };
        choices.DefaultRequestCulture = new RequestCulture(tradition, tradition);
        choices.SupportedCultures = supportedCultures;
        choices.SupportedUICultures = supportedCultures;
    });

    builder.Providers.AddRazorPages();

    // Authorization providers...

    // Configuration providers...

    // Different utility providers...

    // Id providers...

    // Logging configuration

    var app = builder.Construct();

    // Configure the HTTP request pipeline.
    if (!app.Surroundings.IsDevelopment())
    {
        app.UseExceptionHandler("/Error");
        // The default HSTS worth is 30 days. You could need to change this for manufacturing eventualities, see https://aka.ms/aspnetcore-hsts.
        app.UseHsts();
    }

    app.UseHttpsRedirection();
    app.UseStaticFiles();

    app.UseRouting();

    var localizationOptions = app.Providers.GetService<IOptions<RequestLocalizationOptions>>().Worth;
    app.UseRequestLocalization(localizationOptions);

    app.UseAuthentication();
    app.UseAuthorization();

    app.UseMiddleware<LogMiddleware>();
    app.UseMiddleware<OnboardingMiddleware>();

    app.MapRazorPages();

    // Static information won't load in any surroundings besides Improvement with out this.
    StaticWebAssetsLoader.UseStaticWebAssets(app.Surroundings, app.Configuration);

    logger.Information($"Utility beginning in surroundings: {app.Surroundings.EnvironmentName}");
    app.Run();

} catch (Exception ex)
{
    logger.Deadly(ex, "Stopped program due to exception");
    throw;
}
lastly
{
    // Guarantee to flush and cease inner timers/threads earlier than application-exit (Keep away from segmentation fault on Linux)
    NLog.LogManager.Shutdown();
}

To repair the issue the place AM and PM present as a.m and p.m, I modified the DateTimeFormat as follows:


    CultureInfo tradition = new CultureInfo("en-CA");
    tradition.DateTimeFormat = new DateTimeFormatInfo
    {
        ShortDatePattern = "yyyy-MM-dd",
        LongDatePattern = "yyyy-MM-dd hh:mm:ss tt",
        ShortTimePattern = "hh:mm:ss tt",
        LongTimePattern = "hh:mm:ss tt",
        FullDateTimePattern = "yyyy-MM-dd hh:mm:ss tt",
        DateSeparator = "-",
        TimeSeparator = ":",
        AMDesignator = "AM",
        PMDesignator = "PM"
    };

This had no have an effect on on how DateTimes have been displayed on cell. In brief, it appears as if the DateTimeFormatInfo configuration has no impact when viewing the applying from a cell system. My utility is deployed on IIS.



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments