服务器中的日期时间冲突 (dd/mm/yyyy)

问题描述

当我将我的剃刀页面应用程序上传到服务器时,总是收到此错误“值 '14/09/2022' 对 ...* 无效。”我可以找出问题,格式被解释为 mm/dd/yyyy。我无法更改服务器的系统日期格式。

所以我所做的是通过 IIS 管理器更改了我的应用程序文化和 UI 文化。

enter image description here

即使在更改之后,它仍然显示相同的问题。我使用 Bootstrap 日期选择器。 任何帮助将不胜感激。谢谢。

已编辑

Startup.cs

public class CustomDateConverter : JsonConverter<DateTime>
        {
            public override DateTime Read(ref Utf8JsonReader reader,Type typeToConvert,JsonSerializerOptions options)
            {
                Debug.Assert(typeToConvert == typeof(DateTime));
                return DateTime.Parse(reader.GetString());
            }

            public override void Write(Utf8JsonWriter writer,DateTime value,JsonSerializerOptions options)
            {
                writer.WriteStringValue(value.ToUniversalTime().ToString("dd'/'mm'/'yyyy"));
            }
        }

public void ConfigureServices(IServiceCollection services)
        {
            services.AddRazorPages();

            services.AddDbContext<ApplicationDbContext>(options =>
                    options.UseLoggerFactory(LoggerFactory.Create(builder => builder.AddDebug()))
                    .UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

            services.AddSession(options => {
                options.IdleTimeout = TimeSpan.FromMinutes(30);
                options.Cookie.HttpOnly = true;
                options.Cookie.IsEssential = true;
            });
            services.AddRazorPages().AddJsonOptions(options =>{
                options.JsonSerializerOptions.Converters.Add(new CustomDateConverter());
            });
            services.AddMemoryCache();
        }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)