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.
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.
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.
milliseconds are always three digit #54.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With