DateTime format not showing correctly on iPhone in ASP.NET web application

I have a razor pages web application that shows DateTimes throughout the application. Everything works great on a desktop browser at all media sizes (including mobile). But when I view the application on my iPhone (using Safari or Google Chrome) the DateTime formats do not show the same as they would on desktop.

For example, a DateTime value of 2024-06-15 11:25:54 PM on Desktop, will show as 2024-06-15 11:25:54 p.m on mobile.

This is my program.cs file:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>// Early init of NLog to allow startup and exception logging, before host is built
var logger = NLog.LogManager.Setup().LoadConfigurationFromAppSettings().GetCurrentClassLogger();
try
{
var builder = WebApplication.CreateBuilder(args);
builder.Configuration.AddEnvironmentVariables();
CultureInfo culture = new CultureInfo("en-CA");
culture.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.Services.Configure<RequestLocalizationOptions>(options =>
{
var supportedCultures = new[]
{
new CultureInfo("en-CA"),
};
options.DefaultRequestCulture = new RequestCulture(culture, culture);
options.SupportedCultures = supportedCultures;
options.SupportedUICultures = supportedCultures;
});
builder.Services.AddRazorPages();
// Authorization services...
// Configuration services...
// Other application services...
// Identity services...
// Logging configuration
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
var localizationOptions = app.Services.GetService<IOptions<RequestLocalizationOptions>>().Value;
app.UseRequestLocalization(localizationOptions);
app.UseAuthentication();
app.UseAuthorization();
app.UseMiddleware<LogMiddleware>();
app.UseMiddleware<OnboardingMiddleware>();
app.MapRazorPages();
// Static files will not load in any environment except Development without this.
StaticWebAssetsLoader.UseStaticWebAssets(app.Environment, app.Configuration);
logger.Info($"Application starting in environment: {app.Environment.EnvironmentName}");
app.Run();
} catch (Exception ex)
{
logger.Fatal(ex, "Stopped program because of exception");
throw;
}
finally
{
// Ensure to flush and stop internal timers/threads before application-exit (Avoid segmentation fault on Linux)
NLog.LogManager.Shutdown();
}
</code>
<code>// Early init of NLog to allow startup and exception logging, before host is built var logger = NLog.LogManager.Setup().LoadConfigurationFromAppSettings().GetCurrentClassLogger(); try { var builder = WebApplication.CreateBuilder(args); builder.Configuration.AddEnvironmentVariables(); CultureInfo culture = new CultureInfo("en-CA"); culture.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.Services.Configure<RequestLocalizationOptions>(options => { var supportedCultures = new[] { new CultureInfo("en-CA"), }; options.DefaultRequestCulture = new RequestCulture(culture, culture); options.SupportedCultures = supportedCultures; options.SupportedUICultures = supportedCultures; }); builder.Services.AddRazorPages(); // Authorization services... // Configuration services... // Other application services... // Identity services... // Logging configuration var app = builder.Build(); // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) { app.UseExceptionHandler("/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); var localizationOptions = app.Services.GetService<IOptions<RequestLocalizationOptions>>().Value; app.UseRequestLocalization(localizationOptions); app.UseAuthentication(); app.UseAuthorization(); app.UseMiddleware<LogMiddleware>(); app.UseMiddleware<OnboardingMiddleware>(); app.MapRazorPages(); // Static files will not load in any environment except Development without this. StaticWebAssetsLoader.UseStaticWebAssets(app.Environment, app.Configuration); logger.Info($"Application starting in environment: {app.Environment.EnvironmentName}"); app.Run(); } catch (Exception ex) { logger.Fatal(ex, "Stopped program because of exception"); throw; } finally { // Ensure to flush and stop internal timers/threads before application-exit (Avoid segmentation fault on Linux) NLog.LogManager.Shutdown(); } </code>
// Early init of NLog to allow startup and exception logging, before host is built
var logger = NLog.LogManager.Setup().LoadConfigurationFromAppSettings().GetCurrentClassLogger();

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

    builder.Configuration.AddEnvironmentVariables();

    CultureInfo culture = new CultureInfo("en-CA");
    culture.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.Services.Configure<RequestLocalizationOptions>(options =>
    {
        var supportedCultures = new[]
         {
        new CultureInfo("en-CA"),
    };
        options.DefaultRequestCulture = new RequestCulture(culture, culture);
        options.SupportedCultures = supportedCultures;
        options.SupportedUICultures = supportedCultures;
    });

    builder.Services.AddRazorPages();

    // Authorization services...

    // Configuration services...

    // Other application services...

    // Identity services...

    // Logging configuration

    var app = builder.Build();

    // Configure the HTTP request pipeline.
    if (!app.Environment.IsDevelopment())
    {
        app.UseExceptionHandler("/Error");
        // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
        app.UseHsts();
    }

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

    app.UseRouting();

    var localizationOptions = app.Services.GetService<IOptions<RequestLocalizationOptions>>().Value;
    app.UseRequestLocalization(localizationOptions);

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

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

    app.MapRazorPages();

    // Static files will not load in any environment except Development without this.
    StaticWebAssetsLoader.UseStaticWebAssets(app.Environment, app.Configuration);

    logger.Info($"Application starting in environment: {app.Environment.EnvironmentName}");
    app.Run();

} catch (Exception ex)
{
    logger.Fatal(ex, "Stopped program because of exception");
    throw;
}
finally
{
    // Ensure to flush and stop internal timers/threads before application-exit (Avoid segmentation fault on Linux)
    NLog.LogManager.Shutdown();
}

To fix the problem where AM and PM show as a.m and p.m, I modified the DateTimeFormat as follows:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>
CultureInfo culture = new CultureInfo("en-CA");
culture.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"
};
</code>
<code> CultureInfo culture = new CultureInfo("en-CA"); culture.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" }; </code>

    CultureInfo culture = new CultureInfo("en-CA");
    culture.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 affect on how DateTimes were displayed on mobile. In short, it seems as though the DateTimeFormatInfo configuration has no effect when viewing the application from a mobile device. My application is deployed on IIS.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật