How to convert Unix Time to .net DateTime
This article explains how to convert UNIX Datetime to .Net DateTime in local format.
Article Metadata
Compatibility
Platform(s): Windows Phone 7.5
Article
Created: nilay.shah3nov
(26 Aug 2012)
Last edited: hamishwillee
(10 Apr 2013)
UNIX Time
Unix time, or POSIX time, is a system for describing instances in time, defined as the number of seconds that have elapsed since midnight Coordinated Universal Time (UTC), January 1, 1970, not counting leap seconds. It is used widely in Unix-like and many other operating systems and file formats. It is neither a linear representation of time nor a true representation of UTC. Unix time may be checked on some Unix systems by typing date +%s on the command line.
How to Convert Unix Time to .Net System.DateTime
System.DateTime unixTime = new System.DateTime(1970,1,1,0,0,0,0, DateTimeKind.Utc);
DateTime myDate =unixTime.AddSeconds(1258598728).toLocalTime();


Hamishwillee - Thanks!
Hi Nilay
Thanks for this article. Personally I'm always trying to find reference for these types of conversions so this is quite useful.
I've given it a basic edit. You'll note that I've removed the .NET category. As a rule we use Silverlight for .NET on the wiki. I know that they are subtly different, but in general the implementation of .NET we're talking about it silverlight, so if you want the article to be findable, suggest you use both.
In terms of "improvement", what really helps and article is to provide great links to other good resources on the topic. So could you please provide an API reference link to the DateTime object as it appears on Windows Phone?
regards
Hamishhamishwillee 09:52, 27 August 2012 (EEST)
Nilay.shah3nov -
Thanks for feedback.
Added System namespace for DateTime. I hope that was you refer, right?nilay.shah3nov 14:42, 4 September 2012 (EEST)
Hamishwillee - Not quite
Hi Nilay
No :-)
What I mean is that if you want to work with DateTime and you see this article you are likely to then want to find out what else you can do with the class. However if you search on DateTime on google you'll get a million hits. It is helpful to provide link to the precise key classes you talk about.
So for example, in this case, I'd change from
to
Even better, add link to good doc on UNIX datetime too.
Does that make sense?hamishwillee 07:58, 6 September 2012 (EEST)