Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you get the current time in milliseconds (long), in VB.Net?

Tags:

time

vb.net

I'm looking for the equivalent to a Java System.currentTimeMilli(), in VB.NET.

What is the method to call? I know about Datetime.Now, but not about the actual conversion to long milliseconds.


More details about my specific need:

I need to manage a login expiration. So most likely when I log in, I will set a "expiration_time_milli", equal to the current time + the timeout value. Then later, if I want to check if my login is valid, I will check is "expiration_time_milli" is still superior to current time.

like image 395
Gnoupi Avatar asked Dec 08 '10 09:12

Gnoupi


People also ask

How do I get system time in milliseconds?

To get the current time in milliseconds, you just need to convert the output of Sys. time to numeric, and multiply by 1000. Depending on the API call you want to make, you might need to remove the fractional milliseconds.

How do I print the date in milliseconds?

date +"%T. %6N" returns the current time with nanoseconds rounded to the first 6 digits, which is microseconds. date +"%T. %3N" returns the current time with nanoseconds rounded to the first 3 digits, which is milliseconds.

How many digits are in a millisecond?

milliseconds are always three digit #54.


1 Answers

Get the difference between the current time and the time origin, use the TotalMilliseconds property to get time span as milliseconds, and cast it to long.

DirectCast((Datetime.Now - New DateTime(1970, 1, 1)).TotalMilliseconds, Int64)
like image 138
Guffa Avatar answered Oct 12 '22 13:10

Guffa