C#时间格式问题解决,不受系统时间格式影响

陆陆续续写了几个程序,批量导入之后总会遇到这么几台报错的,然后一看就发现是车间设备系统时间格式不同。

所以,本着为现场排忧解难的态度(其实就是懒),格式化时间好了。

代码附上:

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 HH:mm:ss");
            }

 

C#时间格式问题解决,不受系统时间格式影响

上一篇:C#使用Consul集群进行服务注册与发现


下一篇:AcWing 12. 背包问题求具体方案