开发者

How do I get the time difference when the values are stored in strings?

I need to find to the time difference between two values, but the values are in a string format and not in a DateTim开发者_开发知识库e Object. I can use the TimeSpan class only if it is a DateTime Object.

Moreover it is in a YYYY/MM/DD hh:mm:ss.zz format. I can extract the time part alone, that's not a problem. But I am unable to find the difference all the same.


Since you have datetime string in a particular format, you can use DateTime.ParseExact to change the string to Datetime and use the normal operations on it.


You can use DateTime.Parse("[datestring here]") then use the .Subtract() from the object to calculate the difference.

var d1 = DateTime.Parse("");
var d2 = DateTime.Parse("");

var totalMinures = d1.Subtract(d2).TotalMinutes
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜