Reputation: 947
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?
Upvotes: 2
Views: 843
Reputation: 241633
Using Noda Time:
Instant instant = Instant.FromMillisecondsSinceUnixEpoch(1396949418557);
Upvotes: 5
Reputation: 3112
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.
Upvotes: 1
Reputation: 34427
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);
Upvotes: 1