从字符串C#日期时间转换 [英] DateTime conversion from string C#

查看:258
本文介绍了从字符串C#日期时间转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

解决方案

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

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

如果您有约定的某种形式,使您可以决定哪些迄今为止,它指的是在这些情况下,你可以做一些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

这篇关于从字符串C#日期时间转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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