gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 08:56:21 25 4
gpt4 key购买 nike

在表格中,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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com