如何从日期时间获取时间跨度 [英] How to get TimeSpan from DateTime

查看:140
本文介绍了如何从日期时间获取时间跨度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

情景:

第三方Web服务返回日期时间在两个不同的领域,即日期和时间。我需要一种方法来连接成单个字段。

Third party web service returns datetime in two separate fields i.e. date and time. I need a way to concatenate into single field.

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和有没有在那里。 。可能有人让我知道,如果有达到上述一个聪明的办法

I tried to get the TimeSpan part from startTime and got no where. Could someone let me know if there's a smart way to achieve above.

推荐答案

TimeOfDay 是的日期时间的你正在寻找的属性:

TimeOfDay is the property of DateTime that you're looking for:

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

这篇关于如何从日期时间获取时间跨度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆