VB.NET如何使自定义系统时间(实时) [英] VB.NET How to make a custom system time (real-time)

查看:360
本文介绍了VB.NET如何使自定义系统时间(实时)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在VB.Net的项目中停留在这里。我想创建一个用户定义的日期时间函数,该函数不依赖于Ive尝试在网络上搜索的系统时间,但是它们只给了我如何打印当前系统时间的功能。任何想法专家怎样使定制的日期时间每秒更新一次,即实时更新。

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.

推荐答案

您可以在应用程序的开头将 Date.Now 的值保存在全局变量中:

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

Public StartDate As Date = Date.Now

然后可以计算当前日期在任意时间范围内,使用在此代码中任意时刻从该起始日期和当前日期计算出的 TimeSpan

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

选择 ArbitraryStartDate 是您想要的带有 Date 构造函数,如

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

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

这篇关于VB.NET如何使自定义系统时间(实时)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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