C#中的STRING到Date时间 [英] STring to Date time in C#
本文介绍了C#中的STRING到Date时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将日期字段保存到数据库.我在这里创建一个日期,就像我在下面给出的代码一样.我收到错误消息
String was not recognized as a valid DateTime.
这是我正在使用的代码
i want to save date field to database . i am creating a date here like the code i given below . i am getting the error
String was not recognized as a valid DateTime.
here is the code i am using
string res= (DateTime.Now.Date.ToString("dd/MM/yyyy") + " " + txtTimeIn.Text.ToString() + ":00 " + ddlTimeInAMPM.SelectedValue.ToString());
DateTime aaaaaa = (DateTime) (res)
txtTimeIn.Text= 9:00
ddlTimeInAMPM.SelectedValue=AM
我知道将字符串转换为datetime的情况,但是.它最后一次突然起作用了
i know the case of casting string to datetime but . it works last time suddenly it doesnt
推荐答案
以这种方式进行(DateTime.Now.ToString("dd/MM/yyyy")
Make it this way (DateTime.Now.ToString("dd/MM/yyyy")
谢谢您的重播,我解决了我的问题
thank you for your replay i solve my problem
DateTime.Now.Date.ToString("MM/dd/yyyy")
谢谢大家
thank you all
这篇关于C#中的STRING到Date时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文