Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get current timestamp [duplicate]

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

The format should be like this 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
like image 938
Dan Avatar asked Jan 12 '13 14:01

Dan


1 Answers

If I understand correctly, does this work?

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

I've used DateTime.UtcNow in the example, but you can use DateTime.Now depending on how you plan on using the data. See this thread for more information on the difference.

like image 110
keyboardP Avatar answered Sep 23 '22 22:09

keyboardP