我有一个 GridView
和 SqlDataSource
,
我有一个列类型:DateTime
。如果我在 TextBox
中仅输入日期,则时间将为 00:00:00
。如果没有指定,有没有办法自动添加当前时间?
谢谢
最佳答案
当您在 TextBox
中仅键入日期时,您仍然可以提交并将当前时间添加到日期中。
DateTime inputDate = // However you are gathering the date ;
DateTime dateWithCurrentTime = inputDate.Add(DateTime.Now.TimeOfDay);
DateTime 有一个 Add
函数,允许您添加 TimeSpan
来获取新的 DateTime
对象。
如果将当前时间 (DateTime.Now.TimeOfDay
) 添加到您收集的输入中,您将获得一个新的 DateTime
对象,其当前时间为日期和输入的日期。
关于c# - 如果未写入时间,如何在日期时间控件中添加当前时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11108958/