Startup.cs/Configure 设置CultureInfo

    try
            {
                //设置时间格式,避免liunx系统下面时间错误
                var zh = new CultureInfo("zh-CN");
                zh.DateTimeFormat.FullDateTimePattern = "yyyy-MM-dd HH:mm:ss";
                zh.DateTimeFormat.LongDatePattern = "yyyy-MM-dd";
                zh.DateTimeFormat.LongTimePattern = "HH:mm:ss";
                zh.DateTimeFormat.ShortDatePattern = "yyyy-MM-dd";
                zh.DateTimeFormat.ShortTimePattern = "HH:mm:ss";
                IList<CultureInfo> supportedCultures = new List<CultureInfo>
                {
                    zh,
                };
                app.UseRequestLocalization(new RequestLocalizationOptions
                {
                    DefaultRequestCulture = new RequestCulture("zh-CN"),
                    SupportedCultures = supportedCultures,
                    SupportedUICultures = supportedCultures
                });

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

Program (有效)


 public static void Main(string[] args)
        {
            //设置CultureInfo
            CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("zh-CN", true)
            {
                DateTimeFormat ={
                        FullDateTimePattern = "yyyy-MM-ddTHH:mm:ss",
                        LongDatePattern = "yyyy-MM-dd",
                        LongTimePattern = "HH:mm:ss",
                        ShortDatePattern = "yyyy-MM-dd",
                        ShortTimePattern = "HH:mm:ss"
                    }
            };
            ProgramWebApplication.Init<Startup>(args);
            // CreateHostBuilder(args).Build().Run();
        }

Unhandled exception. Unhandled exception. Unhandled exception. Unhandled exception. System.ArgumentOutOfRangeException: The relative expiration value must be positive. (Parameter ‘AbsoluteExpirationRelativeToNow’)

Microsoft.Extensions.Caching.Memory.MemoryCacheEntryOptions.set_AbsoluteExpirationRelativeToNow(Nullable`1 value)
at Microsoft.Extensions.Caching.Memory.MemoryCacheEntryExtensions.SetAbsoluteExpiration(MemoryCacheEntryOptions options, TimeSpan relative)
at RG3.PF.Caching.Memcached.MemoryCacheProvider.Add[T](String key, T value, TimeSpan expiresIn, Boolean isSliding)
at RG3.PF.Caching.Memcached.MemoryCacheProvider.Set[T](String key, T value)

文档更新时间: 2021-07-15 08:00   作者:admin