[英]Retain MM/dd/yyyy format when converting string value to DateTime
I have a string containing value in the format of 11/22/2019 00:00:00我有一个包含值的字符串,格式为 11/22/2019 00:00:00
I want to store this in a DateTime column.我想将其存储在 DateTime 列中。
I have tried this:我试过这个:
DateTime date ;
DateTime dtVal;
// string abcd contains 11/22/2019 00:00:00
abcd = date.ToString("MM/dd/yyyy hh:mm:ss", CultureInfo.InvariantCulture);
if (DateTime.TryParseExact(abcd, "MM/dd/yyyy hh:mm:ss", System.Globalization.CultureInfo.InvariantCulture, DateTimeStyles.None, out converteddate))
{
dtVal = converteddate; // I am getting 22/11/2019 12:00:00
}
I want the dtval value to hold the datetime value as - 11/22/2019 00:00:00我希望 dtval 值将日期时间值保存为 - 11/22/2019 00:00:00
How to achieve this?如何做到这一点? Thanks谢谢
DateTime itself does not have its "natural" format, as John commented - it is internally "just a number";-). DateTime 本身没有它的“自然”格式,正如约翰所评论的那样 - 它在内部是“只是一个数字”;-)。 The ToString()
method depends on Culture
you set. ToString()
方法取决于您设置的Culture
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.