从DateTimePicker中提取TimeOfDay [英] Extracting TimeOfDay from DateTimePicker

查看:74
本文介绍了从DateTimePicker中提取TimeOfDay的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个约会时间选择器。我只需要从中提取时间来保存到数据库(我的数据库的DateTime列)

我试图通过 DateTimePicker1.Value.TimeOfDay 来解决这个问题但是这会给出错误:



类型' System.TimeSpan '的值无法转换为'日期?'。



请帮忙。

谢谢

Hi,
I have a date time picker. I need to extract only time from it to save to database (DateTime column of my DB)
I am trying to get it through DateTimePicker1.Value.TimeOfDay but this gives error:

Value of type 'System.TimeSpan' cannot be converted to 'Date?'.

Please help.
Thanks

推荐答案

你应该了解那里没有从时间跨度到日期的转换或 DateTime 。这不符合逻辑吗?你明白 DateTime TimeSpan 是如何不同的。想象有人告诉你:过去,我花了90天时间学习.NET。你怎么看,我停下来学习它的那一天?你不能回答,是吗? :-)所以,这部分问题毫无意义,让我们忘掉它。



但你不需要那样。 DateTimePicker 实际上为您提供了 System.DateTime 值,您可以获得当天的时间。请参阅:

http://msdn.microsoft.com /en-us/library/system.datetime.timeofday.aspx [ ^ ]。



-SA
You you should understand there is no conversion from time span to date or DateTime. Isn't it logical? Do you understand how DateTime and TimeSpan are different. Imaging someone told you: "In the past, I've spent 90 days learning .NET. How do you think, on what day I stopped to learn it?" You wouldn't be able to answer, would you? :-) So, this part of question makes no sense, let's forget it.

But you don't need that. DateTimePicker actually gives you System.DateTime value, and you can get just the time of the day. Please see:
http://msdn.microsoft.com/en-us/library/system.datetime.timeofday.aspx[^].

—SA


这篇关于从DateTimePicker中提取TimeOfDay的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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