Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从表中提取时间数据并将其放入TimeSpan_C#_.net_Mysql - Fatal编程技术网

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

C# 从表中提取时间数据并将其放入TimeSpan,c#,.net,mysql,C#,.net,Mysql,在表中,是否有人知道如何选择指定的行并在指定的列中获取时间数据,然后将数据放入TimeSpan中 DataRow[] selectIDRow = RetailCamDataSet1.Tables["smBranchWorkingDayInfo"].Select("ID=" + ID); foreach (DataRow row in getTimeDifference) { TimeSpan startTime = new TimeSpan(); //Need to put the da

在表中,是否有人知道如何选择指定的行并在指定的列中获取时间数据,然后将数据放入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
    }

如果确定时间列的文本格式正确,可以使用
TimeSpan.Parse()


是的,我正在使用TimeSpan.Parse()。这是我的代码,它是有效的!:)


您在指定列中的时间数据是什么格式的?Thx对于您的信息,也可以在将来用作参考。
TimeSpan startTime = TimeSpan.Parse(row["time"].ToString());
foreach (DataRow row in RetailCamDataSet1.Tables["smBranchWorkingDayInfo"].Select("ID=" + convertedBranchID))
                {
                    var sTime = DateTime.Parse(row["SunFromTime"].ToString());
                    int sHour = sTime.Hour,
                        sMinute = sTime.Minute,
                        sSecond = sTime.Second;

                    var eTime = DateTime.Parse(row["SunToTime"].ToString());
                    int eHour = eTime.Hour,
                        eMinute = eTime.Minute,
                        eSecond = eTime.Second;

                    TimeSpan startTime = new TimeSpan(sHour, sMinute, sSecond);
                    TimeSpan endTime = new TimeSpan(eHour, eMinute, eSecond);
                    TimeSpan timeDifference = new TimeSpan();

                    timeDifference = endTime.Subtract(startTime);

                    double minutes = timeDifference.TotalMinutes;

                    normalCount = minutes / 15;