user489041 user489041 - 1 month ago 7
C# Question

Get Epoch in C# for GMT

I need to get number of milliseconds from the epoch in GMT.

Can I use this for the GMT part:

DateTime.Now.ToUniversalTime()


What about the number of milliseconds since the epoch?

Answer Source

This should give you a TimeZone agnostic answer.

TimeSpan t = DateTime.UtcNow - new DateTime(1970, 1, 1);
double ms = t.TotalMilliseconds ;