Reputation: 12852
My client application requires, from the server, "how many seconds between some value and 1970".
I'm testing this with the following code:
var span = (DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0).ToLocalTime()).TotalSeconds;
return span;
But if I convert the result from this unix time, I get something that's an hour later than now, so my client application is not behaving as expected.
What's going on?
Upvotes: 0
Views: 865
Reputation: 761
try:
TimeSpan span = DateTime.Now.Subtract(new DateTime(1970,1,1,0,0,0));
Then use span.TotalSeconds
Upvotes: -1
Reputation: 4520
Try with UTC times:
(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).TotalSeconds;
Upvotes: 6
Reputation:
Is this what you're looking for?
var span = (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
return span;
Upvotes: 2