Java System.currentTimeMillis() equivalent in C#

yash picture yash · Nov 14, 2008 · Viewed 55.6k times · Source

What is the equivalent of Java's System.currentTimeMillis() in C#?

Answer

Jon Skeet picture Jon Skeet · Nov 14, 2008

An alternative:

private static readonly DateTime Jan1st1970 = new DateTime
    (1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);

public static long CurrentTimeMillis()
{
    return (long) (DateTime.UtcNow - Jan1st1970).TotalMilliseconds;
}