以datetime格式存储值的问题 [英] problem storing value in datetime format

查看:85
本文介绍了以datetime格式存储值的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个文本框和一个下拉列表..我在第一个文本框输入日期,在第二个文本框中输入时间,从dropdownlist.i选择上午或下午想要将这些数据存储在一个日期时间格式的列中。我帮助吗?

i have two textbox and one dropdownlist..i am entering date in 1st textbox,time in 2nd textbox and selecting am or pm from dropdownlist.i want to store this data in one column which is datetime format.plz help me?

推荐答案

参考下面的链接

http://www.csharp-examples.net/string-format-datetime/ [ ^ ]

http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx [ ^ ]

Easy String to DateTime,DateTime to String and Formatting [ ^ ]
refer Below Links
http://www.csharp-examples.net/string-format-datetime/[^]
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx[^]
Easy String to DateTime, DateTime to String and Formatting[^]


将所有值归入单弦。

Club all the values into single string.
Page_Load()
{ 
   string strDate = textbox1.text + " " + textbox2.text + " " + dropdownlist.selectedtext;
   DateTime datetime = DateTime.Parse(strDate);
   Console.WriteLine(datetime.ToString());
}





我试过上面的代码,它按预期工作。



请注意:如果您确保在文本框中输入正确的日期和时间格式,此解决方案将起作用,否则它将为您提供例外。



I have tried above code, it is working as expected.

Please note: This solution will work if you ensure that correct format of date and time is entered in the textboxes else it will give you an exception.


这篇关于以datetime格式存储值的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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