C#如何查找输入日期的日期格式? [英] C# How to find the date format of the input date ?

查看:110
本文介绍了C#如何查找输入日期的日期格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要根据格式获取输入日期的日期格式和进一步处理。如何在不使用TRY CATCH的情况下实现这一目标?请帮助。

Hi , I need to get the date format of the input date and process further according to the format . How can i achieve this without using TRY CATCH ? Please Help.

推荐答案

请参阅我对该问题的评论。此外,原则上这是不可能的,因为'12 / 09/2012'可以被成功识别为以太mm / dd / yyyy或dd / mm / yyyy。 所以,整个想法都是错误的。



我必须说,不使用Y如何做X之类的问题只是反击-productive。你真的需要解释为什么你需要这种方式。



太糟糕了你没有分享你想要使用的UI类型,因为这是非常好的解决方案将使用一种或另一种类型的 DateTimePicker



-SA
Please see my comment to the question. Besides, this is impossible in principle, because '12/09/2012' can be successfully recognized as ether "mm/dd/yyyy" or "dd/mm/yyyy". So, the whole idea is just wrong.

I must say, questions like "how to do X without using Y" are simply counter-productive. You really need to explain why do you need it this way.

It's too bad you did not share what type of UI you want to use, because the really good solution would be using one or another type of DateTimePicker.

—SA


我认为对于你的情况 DateTime.TryParseExact()是一个很好的选择,看看输入sting中的格式。参见..

如何检查日期格式-c-sharp [ ^ ]

查找日期时间格式的字符串日期在c-sharp [ ^ ]
I think for your case DateTime.TryParseExact() would be a good option to see which format is in a input sting.See..
How-to-check-date-format-c-sharp[^]
Find-out-the-date-time-format-of-string-date-in-c-sharp[^]


这篇关于C#如何查找输入日期的日期格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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