在 VB.NET 中获取系统时间

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2294775/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 14:42:43  来源:igfitidea点击:

Get system time in VB.NET

vb.net

提问by user225269

How do I get the system time using VB.NET and copy it into the clipboard automatically?

如何使用VB.NET获取系统时间并自动复制到剪贴板?

Is there a built-in function in VB.NET for this?

VB.NET 中是否有内置函数?

回答by JaredPar

I'm not sure what you mean by System Time, but if it's just the string representation of the current time then you can do the following.

我不确定您所说的系统时间是什么意思,但如果它只是当前时间的字符串表示,那么您可以执行以下操作。

ClipBoard.SetText(DateTime.Now.ToString())

This code will work in both Windows Forms and WPF.

此代码适用于 Windows 窗体和 WPF。

回答by Gerrie Schenck

Use DateTime.Nowto get the time and Google for the code to copy to the clipboard.

使用DateTime.Now获取时间和谷歌以将代码复制到剪贴板。

Or take a look at thispost.

或者看看这个帖子。

回答by GiPo

Better use the DateTime.UtcNowmethod. It returns time without local format and DST offset.

最好用这个DateTime.UtcNow方法。 它返回没有本地格式和 DST 偏移量的时间。

UTCwill keep you out of trouble when storing data. You can always format to local when export/display is needed.

UTC将让您在存储数据时免于麻烦。当需要导出/显示时,您始终可以格式化为本地。