字符串转换的日期格式日期时间MM / DD / YYYY当系统日期为甲酸DD / MM / YYYY [英] Convert date format of string to datetime MM/dd/yyyy when system date formate is dd/MM/yyyy

查看:499
本文介绍了字符串转换的日期格式日期时间MM / DD / YYYY当系统日期为甲酸DD / MM / YYYY的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要转换成字符串格式MM / DD / YYYY为datetime格式MM / DD / YYYY当系统日期格式为DD / MM / YYYY的日期。

I need convert the date of string format 'MM/dd/yyyy' to datetime format 'MM/dd/yyyy' when the system date format is 'dd/MM/yyyy'.

推荐答案

的DateTime 存储日期数值,而不是作为一个字符串。所以要求一个的DateTime 类型的格式MM / DD / YYYY的没有太大的意义。如果要显示在WPF控制权的日期,则默认为的显示的符合系统日期格式的字符串。但是,这仅仅是一个的显示字符串的可以操作使用上面的链接提到的格式字符串。使用@ Sajeetharan的代码将创建一个的DateTime 结构与内部正确的值。如何显示它是由你和你的字符串格式化的选择。

DateTime stores a date as a numerical value, not as a string. So asking for a DateTime type of format 'MM/dd/yyyy' doesn't make much sense. If you are displaying the date in a WPF control, it will default to displaying a string that conforms to the system date format. But that is just a display string that you can manipulate using the format strings alluded to in the links above. Using @Sajeetharan's code will create a DateTime struct with the correct value internally. How you display it is up to you and your string formatting choices.

这同样适用于存储在类型为日期时间的数据库列的日期。值被数字存储。您的查询编辑器的显示的可能在相同的格式,你的系统设置的值。如果日期存储为一个字符串,然后再次,@ Sajeetharan的代码是将数据库字符串成的DateTime 结构转换的正确方法。

The same goes for dates stored in a database column of type 'datetime'. The value is stored numerically. Your query editor will display the value likely in the same format as your system settings. If the date is stored as a string, then again, @Sajeetharan's code is the correct way to convert the database string into a DateTime struct.

这篇关于字符串转换的日期格式日期时间MM / DD / YYYY当系统日期为甲酸DD / MM / YYYY的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆