.net core 下编码问题

System.Globalization.CultureInfo.CurrentCulture
                = new System.Globalization.CultureInfo("zh-CN", true)
                {
                    DateTimeFormat = { ShortDatePattern = "yyyy-MM-dd",
                    FullDateTimePattern = "yyyy-MM-dd HH:mm:ss", LongTimePattern = "HH:mm:ss" }
                };
            System.Globalization.CultureInfo.CurrentUICulture
                = new System.Globalization.CultureInfo("zh-CN", true)
                {
                    DateTimeFormat = { ShortDatePattern = "yyyy-MM-dd",
                    FullDateTimePattern = "yyyy-MM-dd HH:mm:ss", LongTimePattern = "HH:mm:ss" }
                };
            System.Globalization.CultureInfo.DefaultThreadCurrentCulture
                = new System.Globalization.CultureInfo("zh-CN", true)
                {
                    DateTimeFormat = { ShortDatePattern = "yyyy-MM-dd",
                    FullDateTimePattern = "yyyy-MM-dd HH:mm:ss", LongTimePattern = "HH:mm:ss" }
                };
            System.Globalization.CultureInfo.DefaultThreadCurrentUICulture
                = new System.Globalization.CultureInfo("zh-CN", true)
                {
                    DateTimeFormat = { ShortDatePattern = "yyyy-MM-dd",
                    FullDateTimePattern = "yyyy-MM-dd HH:mm:ss", LongTimePattern = "HH:mm:ss" }
                };
View Code

.net core 默认编码格式没注意,时间类型 直接默认字符串的话:月/日 年 时:分:秒,一般会和我们的用法不一致。(tostring("yyyy-MM-dd HH:mm:ss"),则是重新制定format,就不受制于编码了)

上述代码,适用于全局。

写在program中的第一行。

posted @ 2018-05-28 15:25  Eric-Lee  阅读(326)  评论(0编辑  收藏  举报