从字符串获取值到datetime.today.addhours [英] getting value from string to datetime.today.addhours
问题描述
你好,
我正在尝试基于20分钟时间间隔的开始时间和结束时间在c#中创建动态时隙.起始时间和结束时间m来自输入文本框的用户.我想将这些时隙存储在数据库(SQL Server)中.我已经为静态值创建了时隙.但是当我尝试获取用户给定的字符串值时,这里出现了问题,如何从字符串获取值到datetime.today.addhours ???
谢谢
Hello,
I am trying to create dynamic time slots in c# based on the start time and end time with 20 minutes time interval. the start time and end time m getting from the user who enters in the textboxes. I want to store those time slots in the database (sql server). I have create time slots for static value. but when i am trying to fetch the value which is given by user which is string here is the problem how can i get the values from string to datetime.today.addhours???
Thank you
推荐答案
AddHours
方法获得double
( ^ ])作为参数,因此您必须将字符串转换为双精度值(尝试使用 ^ ]方法).
AddHours
method gets adouble
(MSDN[^]) as argument, hence you have to convert your string to a double value (try the Double.Parse[^] method).
从您的解释中,我可以得出这个答案.让我知道这是否适合.
Hi,
From your explanation, I could come up with this answer. Let me know if this suits.
DateTime startTime =Convert.ToDateTime(dttimeslot.Rows[0]["day_start_time"].ToString());
DateTime endTime=Convert.ToDateTime(dttimeslot.Rows[0]["day_end_time"].ToString());
while (startTime < endTime)
{
startTime = startTime.AddMinutes(inc);
//Your logic here
}
这有帮助吗?
Does this help?
这篇关于从字符串获取值到datetime.today.addhours的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!