pr0g33k

Convert a Unix Timestamp to System.DateTime

I'm working on a scheduler using WebApi and FullCalendar. (I'll post it as soon as I finish.) When populating the events in an agenda view with JSON, FullCalendar will send a start date and an end date for the displayed calendar days. The dates are sent using a Unix timestamp, though. Not being a Unix guy, I had to look it up. It turns out that Unix Epoch is the 1st of January 1970 00:00:00 GMT. A Unix timestamp is the number of seconds since that date and time. So, to convert the date to a System.DateTime date, use the following:

DateTime startDate = new DateTime(1970, 1, 1, 0, 0, 0).AddSeconds(start);
DateTime endDate = new DateTime(1970, 1, 1, 0, 0, 0).AddSeconds(end);
    

Simple!

Posted on 5/2/2013 at 06:05 PM
Tags: C#

Comments:

Leave a comment
  1. CAPTCHA