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" } };
.net core 默認編碼格式沒注意,時間類型 直接默認字符串的話:月/日 年 時:分:秒,通常會和咱們的用法不一致。(tostring("yyyy-MM-dd HH:mm:ss"),則是從新制定format,就不受制於編碼了)ide
上述代碼,適用於全局。編碼
寫在program中的第一行。spa