VB.NET How to make a custom system time (real-time

2019-09-02 14:18发布

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条回答
时光不老,我们不散
2楼-- · 2019-09-02 14:59

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)

enter image description here

查看更多
登录 后发表回答