Question

I cannot for the life of me deserialize a date string which I am told is ISO 8601 (e.g. '1396949418557') to a C# DateTime object.

I really like what I've read about Noda Time, and I am using JSON.NET. Has anyone come across this?

Was it helpful?

Solution 2

It looks like a unix timestamp. Try this:

var unixEraStart = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
var dateTime = unixEraStart.AddMilliseconds(1396949418557);

OTHER TIPS

Using Noda Time:

Instant instant = Instant.FromMillisecondsSinceUnixEpoch(1396949418557);

Your string looks like a Javascript timestamp (milliseconds since 1970/01/01, effectively 1000 * unix time).

I've never used nodatime, but it looks like that library defines time in terms of ticks since the unix epoch, with 10,000 ticks = 1 millisecond. So if you do an Int64.Parse of your string, then multiply it by 10,000, you should be able to construct a nodatime date object with that value.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top