Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/291.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.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# 如何从DateTime获取时间跨度_C#_.net - Fatal编程技术网

C# 如何从DateTime获取时间跨度

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

情景:

第三方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部分,但没有找到任何位置。有人能告诉我是否有一个聪明的方法来实现上述目标。

是您正在寻找的DateTime的属性:

TimeSpan timeOfDay = startTime.TimeOfDay;
DateTime fullStartDateTime = startDate.Add(timeOfDay);

timespan fr=new timespan();
fr.parse(字符串日期)