vb.net 如何获取当前时间戳

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14294156/
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 16:34:22  来源:igfitidea点击:

How to get current timestamp

vb.netdatetime

提问by Dan

I am connecting to an API and one of the parameters is Long (13 digits)to hold the current timestampin VB.Net which represents milliseconds passed from 0:00:00 01.01.1970 in GMTuntil the current time.

我正在连接到一个 API,其中一个参数是 Long (13 位数字)来保存timestampVB.Net 中的电流,它表示从0:00:00 01.01.1970 in GMT当前时间过去的毫秒数。

The format should be like this 1290932238757

格式应该是这样的 1290932238757

I tried this syntex :

我试过这个语法:

DirectCast((Datetime.Now - New DateTime(1970, 1, 1)).TotalMilliseconds, Int64)

But the output was :

但输出是:

01/12/2013 02:06:24

回答by keyboardP

If I understand correctly, does this work?

如果我理解正确,这行得通吗?

Dim milliseconds = CLng(DateTime.UtcNow.Subtract(New DateTime(1970, 1, 1))
                                                       .TotalMilliseconds)

I've used DateTime.UtcNowin the example, but you can use DateTime.Nowdepending on how you plan on using the data. See this threadfor more information on the difference.

DateTime.UtcNow在示例中使用过,但您可以DateTime.Now根据您计划如何使用数据来使用。有关差异的更多信息,请参阅此线程