从字符串 C# 转换日期时间 [英] DateTime conversion from string C#
本文介绍了从字符串 C# 转换日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个字符串 (642014
),格式为 Mdyyyy
.
我想将字符串转换为 04062014
(ddMMYYYY
).
我已经尝试了以下代码.
请帮忙.
I have a string (642014
) which is in the format Mdyyyy
.
I want to convert the string to 04062014
(ddMMYYYY
).
I have tried the following code.
Please help.
DateTime.TryParseExact("642014", "MMddyyyy",
CultureInfo.InvariantCulture,
DateTimeStyles.None, out "04062014");
推荐答案
这不是有效的日期格式.
That's not a valid date format.
要强调的问题是1112014
是11 月 1 日
还是 1 月 11 日
?
To highlight the issue is 1112014
the 1st of Nov
or 11th of Jan
?
如果您有某种约定允许您确定在这些情况下它指的是哪个日期,您可以进行某种预处理或手动解析字符串,但您不会找到任何内置"的内容对于那种格式
If you have some sort of convention that allows you to determine which date it refers to in these instances you could do some sort of pre - processing or parse the string manually but you're not going to find anything 'built in' for that format
这篇关于从字符串 C# 转换日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文