C# 如何从DateTime获取时间跨度
情景: 第三方web服务在两个单独的字段(即日期和时间)中返回C# 如何从DateTime获取时间跨度,c#,.net,C#,.net,情景: 第三方web服务在两个单独的字段(即日期和时间)中返回datetime。我需要一种连接到单个字段的方法 e.g. startDate='24-06-2012' startTime='1-01-1970 1:00:00 AM' Expected result: fullStartDateTime='24-06-2012 1:00:00 AM' 我试着从startTime获取TimeSpan部分,但没有找到任何位置。有人能告诉我是否有一个聪明的方法来实现上述目标。是您正在寻找的D
datetime
。我需要一种连接到单个字段的方法
e.g.
startDate='24-06-2012'
startTime='1-01-1970 1:00:00 AM'
Expected result:
fullStartDateTime='24-06-2012 1:00:00 AM'
我试着从startTime获取TimeSpan部分,但没有找到任何位置。有人能告诉我是否有一个聪明的方法来实现上述目标。是您正在寻找的DateTime的属性:
TimeSpan timeOfDay = startTime.TimeOfDay;
DateTime fullStartDateTime = startDate.Add(timeOfDay);
timespan fr=new timespan();
fr.parse(字符串日期)