Reputation: 28304
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?
Upvotes: 3
Views: 3726
Reputation: 3131
You can do as easily as below in newer .NET versions;
DateTimeOffset.Now.ToUnixTimeMilliseconds()
Refer docs.
Upvotes: 0
Reputation: 44278
This should give you a TimeZone agnostic answer.
TimeSpan t = DateTime.UtcNow - new DateTime(1970, 1, 1);
double ms = t.TotalMilliseconds ;
Upvotes: 8