VB.NET How to make a custom system time (real-time) [closed]

不打扰是莪最后的温柔 提交于 2020-01-06 11:56:25

问题


So Im stuck here on my project in VB.Net . I wanted to make a user defined date time function that is not dependent on the system time Ive tried to search on the net but they only gave me how to print current system time. Any idea guys how to make a customized date time updating every seconds in other words real time .

any answers will be entertained thanks in advance.


回答1:


You can save the value of Date.Now at the start of your application in a global variable:

Public StartDate As Date = Date.Now

Then you can calculate the current date in your arbitrary time scale, using the TimeSpan calculated from this starting date and the current date, at any point in your code:

Dim Elapsed As TimeSpan = Date.Now - StartDate
Dim NewDate As Date = ArbitraryStartDate + Elapsed

Choose ArbitraryStartDate to be any date you like with the Date constructor like

Dim ArbitraryStartDate As Date = New Date(1983, 05, 03)



来源:https://stackoverflow.com/questions/32067087/vb-net-how-to-make-a-custom-system-time-real-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!