参考文档:https://blog.csdn.net/i2blue/article/details/105798392
背景:
.net core 项目部署在 中标麒麟V7.0 上面,DateTime.now()方法,输出的结果带中文 上午 下午
修改前.png
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("zh-CN", true) { DateTimeFormat = { ShortTimePattern = "HH:mm:ss", ShortDatePattern = "yyyy-MM-dd", FullDateTimePattern = "yyyy-MM-dd HH:mm:ss", LongDatePattern = "yyyy-MM-dd", LongTimePattern = "HH:mm:ss" } };
Thread.CurrentThread.CurrentCulture = new CultureInfo("zh-CN", true) { DateTimeFormat = { ShortTimePattern = "HH:mm:ss", ShortDatePattern = "yyyy-MM-dd", FullDateTimePattern = "yyyy-MM-dd HH:mm:ss", LongDatePattern = "yyyy-MM-dd", LongTimePattern = "HH:mm:ss" } };
使用:
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("zh-CN", true) { DateTimeFormat = { ShortDatePattern = "yyyy-MM-dd", FullDateTimePattern = "yyyy-MM-dd HH:mm:ss", LongTimePattern = "HH:mm:ss" } };
DateTime currentTime = DateTime.Now;
修改后.png
网友评论