-2

I have a date in XML:

<time>1340517600</time>

How can I convert it to a DateTime in C#?

Ry-
  • 209,133
  • 54
  • 439
  • 449
CherryPerry
  • 181
  • 2
  • 9

1 Answers1

8

That's a Unix timestamp for "Sun, 24 Jun 2012 06:00:00 GMT".

To convert from a Unix timestamp to a .NET DateTime, look at these questions:

Here is Jon Skeet's solution:

private static readonly DateTime Epoch = new DateTime(1970, 1, 1, 0, 0, 0, 
                                                      DateTimeKind.Utc);

public static DateTime UnixTimeToDateTime(string text)
{
    double seconds = double.Parse(text, CultureInfo.InvariantCulture);
    return Epoch.AddSeconds(seconds);
}

See it working online: ideone

Community
  • 1
  • 1
Mark Byers
  • 767,688
  • 176
  • 1,542
  • 1,434