从字符串C#日期时间转换字符串、日期、时间

2023-09-02 01:37:28 作者:举世温柔

我有一个字符串( 642014 ),它的格式为 Mdyyyy 。 我想字符串转换为 04062014 DDMMYYYY )。 我曾尝试以下code。请帮助。

  DateTime.TryParseExact(642014,MMDDYYYY
                       CultureInfo.InvariantCulture,
                       DateTimeStyles.None,去04062014);
 

解决方案

这不是一个有效的日期格式。

要突出的问题是 1112014 月1日 1月11日的

如何把Excel中的8位的日期字符串转换为日期

如果您有约定的某种形式,使您可以决定哪些迄今为止,它指的是在这些情况下,你可以做一些pre的 - 加工或手工解析字符串,但你不会找到任何该格式内置的

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.

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