Anton Gogolev
Anton Gogolev

Reputation: 115691

Converting Unix Time with Offset to .NET DateTime

I can't get my head around on how to convert something like

1332953228 -14400

to first-class System.DateTime object. This value actually comes from Mercurial an when displayed on the UI is seen as

Wed Mar 28 20:47:08 2012 +0400

Upvotes: 0

Views: 153

Answers (1)

Chris Shaffer
Chris Shaffer

Reputation: 32565

I'm not sure exactly how you should handle the timezone offset, but Unix Time is number of seconds since 1/1/1970. This seems close, though like I said I'm not sure about the offset:

var theDate = new DateTimeOffset(new DateTime(1970, 1, 1).AddSeconds(1332953228), TimeSpan.FromSeconds(-14400));

Upvotes: 1

Related Questions