How do you get the current time in milliseconds (long), in VB.Net?
time, vb.net
Solution
It's somewhat alarming to see all the answers here referring to `DateTime.Now`, which returns the local time (as in "in the system default time zone") - whereas `System.currentTimeMillis()` returns the number of milliseconds since the Unix epoch (1970-01-01T00:00:00Z). All the answers here should probably refer to `DateTime.UtcNow` instead.
Fortunately, somewhat after this question was asked, a much simpler approach has been made available, via `DateTimeOffset.ToUnixTimeMilliseconds()`. So you just need:
Dim millis = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
Problem
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.