Window10系统时间导致时间格式数据带中文

 

Convert.ToDateTime(b).ToString();->1968/3/11 星期一 上午 12:00:00

 

在程序中使用一段代码设置全局时间使用格式:

 if (DateTimeFormatInfo.CurrentInfo != null)
            {
                var type = DateTimeFormatInfo.CurrentInfo.GetType();
                var field = type.GetField("generalLongTimePattern", BindingFlags.NonPublic | BindingFlags.Instance);
                if (field != null)
                field.SetValue(DateTimeFormatInfo.CurrentInfo, "yyyy-MM-dd");
            }

  在使用时间格式的代码前或者在系统全局配置前执行此代码,将导致Convert.ToDateTime(b).ToString()-> '2019-09-18'

 

posted on 2019-07-02 15:10  牛博客  阅读(383)  评论(0编辑  收藏  举报