Monday, July 21, 2014

UNIX time is represented by a single integer that carries the number of seconds that have elapsed since the beginning of 1970 in UTC time.

I am learning of this today in reading about SWT (Simple Web Token) name-value pairs in chapter 10 of Pro ASP.NET Web API Security by Badrinarayanan Lakshmiraghavan. http://www.unixtimestamp.com/index.php has the current time (although you cannot watch it increment in front of you, you have to refresh the browser to see it change) and http://thedude.com/2009/02/unix-time-milestone/ suggests that at 23:31:30 UTC time on 2/13/2009 the time was: 1234567890 ...anyways, you may fish for this stuff in C# like so:

DateTime nineteenSeventy = new DateTime(1970,1,1,0,0,0,0,DateTimeKind.Utc);
TimeSpan timeOnUnixClock = DateTime.UtcNow - nineteenSeventy;
ulong currentUnixTime = Convert.ToUInt64(timeOnUnixClock.TotalSeconds);
ulong halfHourFromNow = currentUnixTime + 1800;

No comments:

Post a Comment