如何将时间跨度转换为特定时间值 [英] how to convert timespan to particualr time value

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

问题描述

我已经开发了一个应用程序
它执行某些任务
根据时间间隔
在app.config文件中设置
这是一个XML文件.
时间间隔在
时间跨度结构

<service updateInterval="0.00:02:00" />



我想将此值转换为特定的
时间是上午10点或任何特定时间.
我该怎么办.
请协助
任何想法.

解决方案

TimeSpan是相对的.您不能将其转换"为日期时间.

您可以执行以下操作:

 DateTime.Now.AddTicks(TimeSpan.FromSeconds( 0 ).Ticks)



只需将其添加到您的相对日期即可.


您可以将datetime对象用作计算的基础.例如

  Dim  dt  As  DateTime =  New  DateTime( 2012  10  4  0  0  0 )
 Dim  sp  As  TimeSpan =  New  TimeSpan(  5000 )
 Dim  ts  As  字符串 =(dt + sp).ToShortTimeString()


如果得到了您,您应该选择(例如)updateStartTime(a DateTime),然后使用updateInterval值对其进行递增.

I have developed a application
which performs certain tasks
based on time interval
set in app.config file
which is a XML file.
the time interval is in
timespan structure
as

<service updateInterval="0.00:02:00" />



I want to convert this value to a particular
time as 10am or any particular time.
How can I do this.
Please assist
any idea.

解决方案

TimeSpan is relative. You cannot "convert" it to date-time.

You can do something like this:

DateTime.Now.AddTicks(TimeSpan.FromSeconds(0).Ticks)



Just add it to your relative date.


You can use a datetime object as base of calculations. For example

Dim dt As DateTime = New DateTime(2012, 10, 4, 0, 0, 0)
Dim sp As TimeSpan = New TimeSpan(5000)
Dim ts As String = (dt + sp).ToShortTimeString()


If I got you, you should choose the (say) updateStartTime (a DateTime) and then increment it using the updateInterval value.


这篇关于如何将时间跨度转换为特定时间值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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