c# - 从表中提取时间数据并将其放入TimeSpan

标签 c# .net mysql

在表格中,any1是否知道如何选择指定行并在指定列中取出时间数据,然后将数据放入TimeSpan中?

DataRow[] selectIDRow = RetailCamDataSet1.Tables["smBranchWorkingDayInfo"].Select("ID=" + ID);
foreach (DataRow row in getTimeDifference)
{
    TimeSpan startTime = new TimeSpan(); //Need to put the data into the bracket instead of using hard code

     TimeSpan endTime = new TimeSpan(20, 00, 00); //Hard coded
     TimeSpan timeDifference = new TimeSpan();

     timeDifference = endTime.Subtract(startTime);

     double minutes = timeDifference.TotalMinutes;

     normalCount = minutes / 15;

最佳答案

您尝试过TimeSpan.Parse()吗?

DataRow[] selectIDRow = RetailCamDataSet1.Tables["smBranchWorkingDayInfo"].Select("ID=" + ID);
    foreach (DataRow row in getTimeDifference)
    {
         DateTime dateTime = DateTime.Parse(row["DateTimeColumn"].ToString());
         TimeSpan timeSpan = TimeSpan.Parse(dateTime.ToString("hh:mm:ss"));
         ... //do whatever you want to do with timeSpan
    }

关于c# - 从表中提取时间数据并将其放入TimeSpan,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9882156/

相关文章:

c# - 如何禁用 ListBox 滚动条的标准上下文菜单?

c# - 为什么Azure Functions不支持System.Text.Json,而每个人在示例中都使用NewtonSoft?

php - 可以使用在同一页面上的表单中选择的值来填充 php/mysql 调用吗?

mysql - mysql 5.5.46和5.6.28中datetime类型的区别

c# - 如何通过反射代码(c#)设置可空类型?

c# - 如何在 WPF 中模拟悬挂电缆?

c# - 带有 Oracle 的 Entity Framework ,NUMBER(10) 个错误

c# - 当发生错误时,我们如何从ServiceStack的JSON Serializer访问数据?

c# - Gremlin.Net 从 Enumerable.SelectIListIterator 对象转换为真实类型

mysql - SQL 查询重复结果