netcore liunx docker modify the default Datetime format

Problem: core project released under liunx docker, using ORM with lambda expression to set the conditions where, when conditions have datetime type of default sql statement generated out of the use of DateTime.ToString () in the following example

SELECT * FROM #table WHERE CreateTime >='01/01/2020 00:00:00'

Mysql performed such mssqlserver or being given, but inconvenient to change the underlying code ORM

Solution:

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            //设置CultureInfo
            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
            });
}

PS: The main case docker there is also a need to set a good area, self-search method

Guess you like

Origin www.cnblogs.com/nickchou/p/12160166.html