在我的專案(.NET 6)中,我從用戶那里獲取日期并將其保存在 SQL Server 中,但是當我從資料庫中獲取該日期時,它顯示為波斯日歷。
例如:
- 入庫日期:2022-06-28
- 取自資料庫的日期:1401/04/07

我在 program.cs 中嘗試過這種方式,但沒有奏效:
builder.Services.Configure<RequestLocalizationOptions>(options =>
{
options.DefaultRequestCulture = new Microsoft.AspNetCore.Localization.RequestCulture("en-US");
options.SupportedCultures = new List<CultureInfo> { new CultureInfo("en-US")};
});
PS:我系統的文化是波斯語
我該如何解決?
uj5u.com熱心網友回復:
嘗試使用此方法,在我的代碼中,它作業正常。
var supportedCultures = new[]
{
new CultureInfo("en-US"),
new CultureInfo("fr"),
};
app.UseRequestLocalization(new RequestLocalizationOptions
{
DefaultRequestCulture = new RequestCulture("en-US"),
// Formatting numbers, dates, etc.
SupportedCultures = supportedCultures,
// UI strings that we have localized.
SupportedUICultures = supportedCultures
});
app.UseStaticFiles()在;之前添加此代碼
測驗結果:

轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/497324.html
標籤:C# asp.net 核心 asp.net-core-mvc .net-6.0
