如何使用C#获取在文本框中输入的日期,如下面的格式所示 [英] How can I get the date entered in the textbox as shown in below formats using C#

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

问题描述

I need to get the date in mm/dd/yyyy with hrs:min:sec but the hrs mins sec should always be in this kind of formats 13:18:46 if afternoon,10:48:00 if morning.How can i do this
also i need to get todays date in the same format







01/29/2018 13:18:46
01/07/2017 10:48:00
06/07/2017 11:38:00





我的尝试:





What I have tried:

i tried so many codes but they are not giving me the correct format that i need

推荐答案

自定义日期和时间格式字符串| Microsoft Docs [ ^ ]



DateTime.TryParseExact方法(字符串,字符串,IFormatProvider,DateTimeStyles,DateTime)(系统) [ ^ ]


不要使用文本框获取日期输入,使用免费提供的正确日历控件。
Don't use text boxes to get date input, use the proper calendar controls that are freely available.


如果您正在尝试使用ASP.Net和C#,那么以下解决方案可以帮助您开始。



[带有时间的Asp.Net日历控件]



如果你需要Win形式的控件和c#,那么下面是一个你可以看出来的例子。



C#DateTimePicker控件 [ ^ ]



对于Win表单示例,您需要添加三个下拉菜单,因为您可以看到它是在Asp.net解决方案中完成的并继续您的解决方案。



注意:请不要复制粘贴提供的样本。通过示例试着看看他们是如何实现他们的需要然后你需要确定实现你的需要需要更改。



以上提供的解决方案对我来说也很好看:))
If you are trying it out with ASP.Net and C# then below solution can help you out to start.

[Asp.Net Calendar control with Time]

If you need a control in Win form and c# then below is an example you can look out.

C# DateTimePicker Control[^]

For the Win form example you need to add three drop downs as you can see it was done in Asp.net solution and proceed with your solution.

N.B: Please don't copy paste the samples provided .Go through the examples try to see how they are achieving their need and then you atry to implement yours with certain changes required.

Tha above solution provided are also looks good for me:)


这篇关于如何使用C#获取在文本框中输入的日期,如下面的格式所示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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